Sunday, November 6, 2022

API - Basics & Best Practices

What is API?

Application Programming Interface (API)is a software that allows two applications to talk with each other.

Eg: When we look in this from the developer side, developer wants to display all the movie details, timings in the web application, then the developer use the APIs to get the movie information from the web server where all the movie details are stored. Then developers can retrieve data from the web server using APIs to display in the web application





Benefits of using APIs

Ease of integration: APIs can be embedded with any type of s/w application, so it can easily integrate with the application and functions between different websites

Reduce Software development effort: Using APIs reduce development efforts,developers can implement APIs of Google Maps to provide the exact store location to visitors

Security: APIs provide a secure communication gateway for different app components to interact and exchange data

REST APIs: REpresentational State Transfer: Its an API that follows a set of rules for an application and services to communicate with each other.

The RESTful API follows the REST architecture constraints and interacts with RESTful web services.



HTTP Methods

GET- To retrieve a resource

POST-To create a new resource

PUT- To update an existing resource

DELETE- To delete a resource


REST API Design Best Practices

1. Use JSON as the Format for Sending and Receiving Data

2. Use Nouns Instead of Verbs in Endpoints

3. Name Collections with Plural Nouns

4. Use Status Codes in Error Handling

5. Use Nesting on Endpoints to Show Relationships

6. Use Filtering, Sorting, and Pagination to Retrieve the Data Requested

7. Use SSL for Security

8. Be Clear with Versioning


For more info, ref

https://www.freecodecamp.org/news/rest-api-best-practices-rest-endpoint-design-examples/