The abbreviation REST stands for "REpresentational State Transfer".
REST APIs are used to call resources and allow the software to communicate based on standardized principles, properties, and constraints.
1οΈβ£ Correct status codes
When developing REST APIs, make sure you use the HTTP status code. This helps your user to know if the request they have made is successful or not.
There are a lot of HTTP status codes. But here are the most common ones:
200Ok
400Bad Request
403Forbidden
404Not Found
500 Internal Server Error
Implement at least these five while building a REST API
2οΈβ£ Using JSON
JSON is commonly used to exchange data between client and server. Although it is derived from JavaScript, it is supported by other major languages, either natively or through libraries.
So using JSON for accepting and responding to requests is the best practice.
3οΈβ£ Nested Endpoints
Nested endpoints are the best practice if nested points are related to the endpoint.
Let's, you can get a list of all the cars using /cars endpoint. If you want to see the cars based on the car manufacturer, you should use an endpoint like /cars/manufacturer.
4οΈβ£ Using SSL Certificate
You can achieve the security of your application by adding a Secure Socket Layer (SSL) certificate. By doing this, you will use HTTPS protocol instead of HTTP and make your site less vulnerable to any malicious attacks.
5οΈβ£ Versioning Your REST API
You should version your REST API if you are introducing any breaking changes. This way, your clients can still access the old version, and their products will not break as soon as you launch a new release.
Let's talk about widely used HTTP request methods and how to test them.
In this thread, we will cover:
- GET
- POST
- PUT
- DELETE
π§΅ππ»
π GET
The GET method is the widely used request method. It is used to get the desired resources from the server.
For example, making a request to the /posts endpoint will return all the available posts.
One thing to note here is that we have used plural noun (/posts) for URL naming.
Using plural nouns for naming URLs is the best practice. It simply reduces the confusion about whether there are one or more posts in the resource collection.
Here are Top 5 Image Search and Image Recognition APIs you can use in your next project.
Thread π§΅ππ»
1οΈβ£ Imgur
- Imgur is an online image sharing and image hosting service. Imgurβs API exposes the entire Imgur infrastructure via a standardized programmatic interface.