RESTFUL API Design – Application Guide

This is a little controversial. Some people like the source URL to have the names and others like to be singular. For example:We recommend using the plural mode, as it ends confusion about whether we want to get a singular or collective source of resources. Also, avoid adding additional items such as attaching ALL to the base URL as follows:Some people may not like this, but we suggest keep this situation uniform throughout the project.Sometimes we need to have an API that shows us something more than ID. In these cases, we can use the query parameters to design API .‘Products? Name =’ abc/ preference to GetProductsbyname/ preference.‘Products? Type =’ xyz/ prefers to GetProductsbyType/.This will avoid the emergence of long URLs and keep the design simple.There are a lot of HTTP code, but most developers eventually use two 200 and 500 codes. This is definitely not a good procedure. Here are some HTTP code.200 OK – This is the most common code used by HTTP, indicating that the operation has been successful.201 Created – This code can be used when the Post method must create a new source.202 AcceptED – This code is used to announce this issue that is requested to the server.400 Bad Request – This code is used when the client’s input validation is unsuccessful.401 Unauthorized / 403 Forbidden – This code is used if the user or system is not allowed to perform specific operations.404 Not Found – This code was used when we were looking for a specific source and not available on the system.500 Internal Server Error – This code is never explicitly issued, but may be issued in case of system error.502 Bad Gateway – This code is used when the server has received an invalid response from its upstream server.API-copying is very important. Many different companies use versions in different ways. Some use duplicates in date, and others use queries parameter. Normally, it is best to keep the version as a prefix for the source. Note the following example:/v1/products /v2/productsWe should also avoid using the following method:/v1.2/productsThe above method means that the API can be changed repeatedly. The dot may also not be easily seen in URL-. So keep it simple. The appropriate procedure is also to always have a back -up. This way, if the API version is changed, consumers will have the opportunity to upgrade to the next version.Using a “pagration” in cases where an API may return a lot of data, it is a necessity, and if the load balance is not properly implemented, the service consumer may disappear. You should always keep in mind that the API design should take into account all possible scenarios.In such cases, the use of Limit and Offset is recommended. For example you can do the following:/products?limit=25&offset=50This will also make you have a default and offset.It is also important to choose the API response method. Most modern apps return JSON answers unless you have an old app that still needs an XML response.It is always good to have a set of error messages that the app will send and receive with the right ID. For example, if you are using Facebook graphs API, it will issue a message as follows in the event of an error:{ "error": { "message": "(#803) Some of the aliases you requested do not exist: products", "type": "OAuthException", "code": 803, "fbtrace_id": "FOXX2AhLh80" } }There are also some examples in which people return a URL with an error message that provides more explanations about the error message as well as the method of managing it.In order for the teams to adhere to specific principles, the use of OpenAPI (+) characteristics can be appropriate. Openapi allows the basic design of the API and then subscribe to consumers in an easy way.So we come to the end of this article. Obviously, if you want to have better relationships, you should use APIs. But if the APIs are badly designed, they may increase confusion. So put your best effort to design them to have a simple implementation.