Some Common Mistakes We Should Never Do While Making a RestFull API

Posted By : Lovish Pahwa | 27-Jun-2017

RestFull API refers to a API which is responsible to transfer a resource in representational state from server to client. for example :- Resource "x" is requested by client then at that time Rest Api role is to transfer that resource "x" in its representational state "y" to the client.

Basically REST refers to "Representational State Transfer" its common features are sclable, good performance, easily modifiable etc

Common mistakes one should never do in Rest Web Services :- 

1.) Bad URL Design :- 

While making a Rest Api, URL design plays a big role. Because Url is the face of your API so it should always proper. API Url should always be short and self documented and  parameters passed in URL should be limited and in proper sequence.

example :- 

Bad Design : -    GET     https://oodleslab.com/*emp_id*/getEmployeeDetails/*group_name* 

                           GET     https://oodleslab.com/201612828/getEmployeeDetails/admin ( bad design i.e. not describing what it is for )

                           This is a example of bad designed API i.e Long and not even little bit self-documented.

 

Good Design :-   GET      https://oodleslab.com/employee/*emp_id*/group/*group_name*

                           GET      https://oodleslab.com/employee/201612828/group/admin ( good design )

                          This URL shows that get employee of id 201612828 and having group "admin". this is called a self-documented API URL.

 

2.) Use of  Wrong Http Method :-

There are several types of HTTP method for different purposes and one should always use http method accc to their requirement. Actually many Some http meyhod are also capable of doing work of some other method. But this flow should never be use because this is not a good practice in documentation HTTP method plays a big role its describes the purpose of Request.
 

example :-

1.)  "POST" is used for sending some data to server ususally in case of new Creation but Post is also capable to get some resource to client but we should never use POST at the place of GET.

2.) Tunneling everything through GET

 

3.) Use Of Wrong Http Response Codes :- 

When a error message is proper and response code as well then it helps developers alot to solve or fix issues. If Error message or response code will not be correct then their are many possibilities of passing away of developer LOL, along it will increase your support tickets count . Clear error messages and good usage of HTTP status code may not be pretty, but it can be the difference between a developer evangelizing your API and an angry tweet. Beyond that, always try to keep your developer friends in mind.

example :-  

If a GET API crash due to "authentication" then response should show that request was unauthorized and having Error Code 401 ( Unauthorized ) and should also contain proper error message.

 

REST style conforms to Web architecture design and, if properly implemented, it allows you to take the full advantage of scalable Web infrastructure. Although you might have reasons for breaking some of REST principles, you should always understand why you are doing so.

 

Thanks

 



 

Related Tags

About Author

Author Image
Lovish Pahwa

Lovish is an experienced Manager with strong knowledge of Spring Framework, Play Framework, Java, Javascript, JQuery, AngularJs, and SQL. He is a great problem solver and always ready for new challenges.

Request for Proposal

Name is required

Comment is required

Sending message..