{"id":14055,"date":"2021-02-05T16:03:47","date_gmt":"2021-02-05T10:33:47","guid":{"rendered":"https:\/\/www.indianic.com\/blog\/?p=14055"},"modified":"2022-10-12T17:00:48","modified_gmt":"2022-10-12T11:30:48","slug":"api-development-practices","status":"publish","type":"post","link":"https:\/\/indianic.devpress.net\/blog\/mobile\/api-development-practices.html","title":{"rendered":"Best practices for API development"},"content":{"rendered":"<h2>Top 12 API Development Practices<\/h2>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-16951\" src=\"https:\/\/www.indianic.com\/blog\/wp-content\/uploads\/2021\/02\/top-12-api-development-services.jpg\" alt=\"Top 12 API Development Practices\" width=\"800\" height=\"540\" srcset=\"https:\/\/indianic.devpress.net\/blog\/wp-content\/uploads\/2021\/02\/top-12-api-development-services.jpg 800w, https:\/\/indianic.devpress.net\/blog\/wp-content\/uploads\/2021\/02\/top-12-api-development-services-300x203.jpg 300w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/p>\n<h3>Use Throttling<\/h3>\n<p>API throttling allows you to control the way an API grants access by setting permissions to validate certain API calls. It limits and controls the data that a user can access through API by defining temporary usage states. As a developer, You can have multiple levels of throttling based on the intended users. For example, you can restrict sensitive information on users below 18 y.o while granting access to the same info for users 18+.<\/p>\n<h3>Allow overriding HTTP methods<\/h3>\n<p>The X-HTTP-Method-Override HTTP works as a custom header with a value of either PUT or DELETE when invoking your Web API via JavaScript or via an XMLHttpRequest object from a web browser using an HTTP POST call. As there are some proxies, who only support POST and GET methods! You can then have a delegating-handler to take the appropriate actions.<\/p>\n<h3>Use SDK and Libraries<\/h3>\n<p>Available resources that contain reusable processes and code help boost the speed of the development process and allows the development teams to work with ease.<\/p>\n<h3>Maintaining tight security practices<\/h3>\n<p>You must ensure that your API is secure through authentication and other methods but not at a heavy standard according to the users who won\u2019t be satisfied spending 5 minutes just to authenticate. Security should go hand in hand with user-friendliness!\u00a0 You can use token-based authentication and\u00a0 SSL\/TLS for security and privacy.<\/p>\n<p>Your API should communicate over secure channels with SSL certification. Defining users per role (admin, viewer, editor, etc) helps to grant permissions accordingly.<\/p>\n<h3>Elaborate proper documentation for your API<\/h3>\n<p>Creating proper documentation stands important for both users and developers. For developers, it allows them the best understanding of the entire process and users to check what is exactly available on your API.<\/p>\n<p>Documentation should provide all details about endpoints, methods, requests and responses, possible case scenarios of responsive code, and throttling limits and it can be published as a browsable web page for the highest clarity.<\/p>\n<h3>Accept and respond with JSON<\/h3>\n<p>REST APIs operate with JSON as a standard for transferring data. Unlike\u00a0 XML that isn\u2019t widely supported by frameworks, the majority of networked technology uses JSON.<\/p>\n<p>JavaScript has built-in methods to encode and decode JSON either through the Fetch API or another HTTP client. We should also make sure that the endpoints return JSON as a response.<\/p>\n<h3>Avoid using verbs in endpoint paths, use nouns instead<\/h3>\n<p>You should use the nouns which represent the entity at the endpoint path that we\u2019re retrieving or manipulating as the pathname as having verbs in our API endpoint paths is unnecessary.<\/p>\n<p>The action should be indicated by the HTTP request method that we\u2019re making. The most common methods include GET, POST, PUT, and DELETE. Where GET retrieves resources. POST submits new data to the server. PUT updates existing data. DELETE removes data. The verbs map to the CRUD operations. And so we should create routes like <b>GET \/articles\/<\/b> for getting news articles and, <b>POST \/articles\/<\/b> to add a new article,<b> PUT \/articles\/:id<\/b> to update the article with the given id. <b>DELETE \/articles\/:id<\/b> is to delete an existing article with the given ID.<\/p>\n<h3>Name your collections with plural nouns<\/h3>\n<p>We should have anime collections with plural nouns to adequate with what\u2019s in our database as tables usually have more than one entry.<\/p>\n<h3>Nest resources for hierarchical objects<\/h3>\n<p>The path of the endpoints that deal with nested resources should be done by appending the nested resource by order: parent resource and paths coming after<\/p>\n<p>We have to make sure that: what we considered a nested resource matches what we have in our database tables.<\/p>\n<h3>Handle errors<\/h3>\n<p>Returning HTTP response to indicate what kind of error occurred helps eliminate confusion for API maintainers. Errors can bring down an entire system. Common types of error HTTP status include:<\/p>\n<ul>\n<li aria-level=\"1\">\u00a0400 Bad request: If the user\u2019s input isn\u2019t validated<\/li>\n<li aria-level=\"1\">401 Unauthorized: if a user isn\u2019t authorized to access a resource.<\/li>\n<li aria-level=\"1\">403 Forbidden: if the user is authenticated yet not allowed access to the resource.<\/li>\n<li aria-level=\"1\">404 Not Found: If the resource is not found.<\/li>\n<li aria-level=\"1\">500 Internal server error: if it is a generic server error<\/li>\n<li aria-level=\"1\">502 Bad Gateway: if the response is invalid<\/li>\n<li aria-level=\"1\">503 Service Unavailable: if the server-side faces issues<\/li>\n<\/ul>\n<h3>Filtering, sorting, paging&#8230;always<\/h3>\n<p>With the growth of your database comes a slower performance. Pagination, sorting and filtering serve to prevent that by determining previously the amount of data meant to be displayed and at what frequency in order to minimize processing time and ensure high-level security.<\/p>\n<p>For example, Filtering helps to narrow down your query results by specified parameters such as date, size, name, etc and pagination helps to serve few results at the time.<\/p>\n<h3>Cache data for higher performance<\/h3>\n<p>Implementing an in-memory database helps to increase the API responsiveness. We can always change the way data is cached according to the changes in our needs.<\/p>\n<h2>Conclusion :<\/h2>\n<p>Well-developed REST API development does not only rely on technical constraints but also takes into consideration the User Experience as an API design solution must be appealing and easy to use. That\u2019s why it needs to be developed with high expertise.<\/p>\n<p><b>If you are looking to give API a part of your business and marketing strategy don&#8217;t hesitate to consult our proficient API engineers and <a href=\"http:\/\/indianic.com\/enquiry\">Let&#8217;s talk about the API&#8217;s needs for your project<\/a>.\u00a0<\/b><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Top 12 API Development Practices Use Throttling API throttling allows you to control the way an API grants access by setting permissions to validate certain API calls. It limits and controls the data that a user can access through API by defining temporary usage states. As a developer, You can have multiple levels of throttling&#8230;<\/p>\n","protected":false},"author":16,"featured_media":14056,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false},"categories":[277],"tags":[2061,2062,2063],"acf":{"show_table_of_content":false},"_links":{"self":[{"href":"https:\/\/indianic.devpress.net\/blog\/wp-json\/wp\/v2\/posts\/14055"}],"collection":[{"href":"https:\/\/indianic.devpress.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/indianic.devpress.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/indianic.devpress.net\/blog\/wp-json\/wp\/v2\/users\/16"}],"replies":[{"embeddable":true,"href":"https:\/\/indianic.devpress.net\/blog\/wp-json\/wp\/v2\/comments?post=14055"}],"version-history":[{"count":0,"href":"https:\/\/indianic.devpress.net\/blog\/wp-json\/wp\/v2\/posts\/14055\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/indianic.devpress.net\/blog\/wp-json\/wp\/v2\/media\/14056"}],"wp:attachment":[{"href":"https:\/\/indianic.devpress.net\/blog\/wp-json\/wp\/v2\/media?parent=14055"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/indianic.devpress.net\/blog\/wp-json\/wp\/v2\/categories?post=14055"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/indianic.devpress.net\/blog\/wp-json\/wp\/v2\/tags?post=14055"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}