SlideShare a Scribd company logo
Modern REST API design principles and
rules
Typically, when updating or developing an API like Newsdata.io which is
a news API for a service to provide news data with quick response time,
there are lengthy discussions about the API’s structure, naming, and
functions. Although, over time, certain rules have emerged that can be
applied to the process and aid in reaching a common ground while
developing.
Let’s get started with some basics
What is an API?
API is an abbreviation for Application Programming Interface. It is a
software interface that allows two applications to communicate with one
another without the need for user intervention.
APIs enable a product or service to communicate with other products and
services without requiring knowledge of how they are implemented.
It facilitates communication between the provider and the client. It is a type
of software interface that provides a service to other programs. An API
specification is a document or standard that describes how to build or use
such a connection or interface.
An API is said to be implemented or exposed by a computer system that
meets this standard. API can refer to either the specification or the
implementation.
What is REST?
REST was created to work specifically with components such as media
components, files, or even objects on a specific hardware device. A RestFul
web service is any web service that adheres to the REST principles. For
working with the required components, a Restful service would use the
standard HTTP verbs GET, POST, PUT, and DELETE. REST is an acronym
that stands for Representational State Transfer.
• GET — requests a representation of the specified resource. Requests
using GET should only retrieve data.
• POST — submits data to the specified resource.
• PUT — replaces all current representations of the target resource with
the request data.
• DELETE — deletes the specified resource.
• PATCH — applies partial modifications to a resource.
When to use REST?
When designing web services, one of the most contentious issues is whether
REST or SOAP should be used. In the following situations, REST services
should be used:
• Limited resources and bandwidth — Because SOAP messages are
heavier in content and consume far more bandwidth, REST should
be used when network bandwidth is limited.
• Statelessness — If there is no need to keep information in a consistent
state from one request to the next, REST should be used. If you need
a proper information flow, where some information from one request
needs to flow into another, SOAP is a better choice. We can use any
online shopping site as an example. Typically, these sites require the
user to first add items that must be purchased to a cart. To complete
the purchase, all of the cart items are transferred to the payment
page. This is an example of an application that would benefit from
the state feature. The cart items’ state must be transferred to the
payment page for further processing.
• Caching — If a large number of requests must be cached, REST is the
ideal solution. Clients may request the same resource multiple times
at times. This may result in an increase in the number of requests
sent to the server. The most frequently used query results can be
saved in an intermediate location by implementing a cache. As a
result, whenever a client requests a resource, it will first check the
cache. If the resources are available, the process will not proceed to
the server. As a result, caching can aid in reducing the number of
trips to the web server.
• Ease of coding — Coding REST Services and then implementing them
is far easier than SOAP. So, if you need a quick win solution for web
services, REST is the way to go.
REST is the most common API architecture in today’s world
(representational state transfer). When using REST, you must adhere to
JSON rules and format your requests in invalid JSON. Aside from that, a
good API should adhere to the following guidelines:
APIs must be separated from the backend, data storage, client, and so on.
Because of security and flexibility, it must be a separate layer.
State less — different requests should have no knowledge of one another
and be processed independently. That also means that each request must
include all of the information required for processing.
API should function in the same way regardless of whether a client sends a
request (e.g. is it a web-server or load-balancer or any other client).
REST APIs typically send static resources, but responses can also contain
executable code in rare cases (such as Java applets). In these cases, the code
should only be executed when needed.
Cacheability — Resources should be cacheable on the client or server-side
whenever possible. The goal is to improve client-side performance while
increasing server-side scalability. However, there are special headers such
as Cache-Control that can be used to control the cache behavior.
Handle errors and return the appropriate error codes. Instead of throwing
an internal error to the user, handle it and send the corresponding code and
message (e.g. 404 — not found.)
Remember that API should be idempotent (that means that can be invoked
many times with the same result). Users can sometimes send duplicate
requests to the API. These duplicate requests may have been made
inadvertently (or intentionally due to timeout or network issues). As a
result, APIs must be fault-tolerant in order for duplicate requests to yield
the same results (only POST request is not idempotent).
To create documentation for your API, use swagger or another tool.
Documentation is a critical component (if someone going to use that API
someday)
There are also some good manners in naming endpoints as well:
• Endpoints should be named with nouns that specify the contents of
the resource rather than adding a verb for the function that is being
performed (e.g., name endpoint /users and use different HTTP
methods for working with the user’s entity rather than creating
several endpoints like /get-user, /add-user, etc.).
• Use clear names: The name of the endpoint should be clear and
intuitive (do not use any shortcuts or abbreviations unless they are
obvious — /ids are understandable and preferable to /identification
numbers).
• Forward slashes are used to create a hierarchy by grouping endpoints
into logical groups (/departments/ids and /departments/managers
are preferable to /departments-ids and /departments-managers).
• Use only lowercase letters: Because URIs are case-sensitive (according
to the specification), it is best to avoid using upper case unless
absolutely necessary.
• Separate words with “-”: different words in the endpoint name are
usually separated by “-” rather than underscores or camel case.
• Avoid special characters: URLs can only be sent and received using
the ASCII character set, so it is possible to use only characters from
that set (also there are some expectable but unsafe characters like “
percent ”,”[]”,”{}”,”|”,” “,”<>” and it is better to try to avoid using
them as well).
The majority of REST APIs are built in conjunction with microservice
architecture. In that case, an API structure like this will allow you to change
the underlying logic, add or remove components, and so on without
changing the communication protocol with other services.
What are the challenges in REST API?
• Lack of Security — Unlike SOAP, REST does not impose any type of
security. This is why REST is ideal for publicly accessible URLs, but
when it comes to passing confidential data between the client and the
server, REST is the worst mechanism to use for web services.
• Lack of state — Most web applications necessitate the use of a stateful
mechanism. For example, if you had a purchasing site with a
shopping cart mechanism, it is necessary to know the number of
items in the shopping cart before the actual purchase is made.
Unfortunately, the client bears the burden of maintaining this state,
which makes the client application heavier and more difficult to
maintain.
References
1. https://levelup.gitconnected.com/good-api-design-bad-api-design-
2405dcdde24c
2. https://newsdata.io
3. https://rajat-testprepkart.medium.com/what-are-restful-web-services-
476dd2f99330
4. https://www.guru99.com/comparison-between-web-services.html

More Related Content

Similar to Modern REST API design principles and rules.pdf

Rest API Automation with REST Assured
Rest API Automation with REST AssuredRest API Automation with REST Assured
Rest API Automation with REST Assured
TO THE NEW Pvt. Ltd.
 
Overview of Rest Service and ASP.NET WEB API
Overview of Rest Service and ASP.NET WEB APIOverview of Rest Service and ASP.NET WEB API
Overview of Rest Service and ASP.NET WEB API
Pankaj Bajaj
 
Rest api design
Rest api designRest api design
Rest api design
Rudra Tripathy
 
REST and RESTful Services
REST and RESTful ServicesREST and RESTful Services
REST and RESTful Services
Damian T. Gordon
 
What are restful web services?
What are restful web services?What are restful web services?
What are restful web services?
Aparna Sharma
 
Restful web-services
Restful web-servicesRestful web-services
Restful web-services
rporwal
 
REST: So What's It All About? (SAP TechEd 2011, MOB107)
REST: So What's It All About? (SAP TechEd 2011, MOB107)REST: So What's It All About? (SAP TechEd 2011, MOB107)
REST: So What's It All About? (SAP TechEd 2011, MOB107)
Sascha Wenninger
 
apidays LIVE Hong Kong 2021 - Multi-Protocol APIs at Scale in Adidas by Jesus...
apidays LIVE Hong Kong 2021 - Multi-Protocol APIs at Scale in Adidas by Jesus...apidays LIVE Hong Kong 2021 - Multi-Protocol APIs at Scale in Adidas by Jesus...
apidays LIVE Hong Kong 2021 - Multi-Protocol APIs at Scale in Adidas by Jesus...
apidays
 
Restful web services by Sreeni Inturi
Restful web services by Sreeni InturiRestful web services by Sreeni Inturi
Restful web services by Sreeni Inturi
Sreeni I
 
REST API Recommendations
REST API RecommendationsREST API Recommendations
REST API RecommendationsJeelani Shaik
 
Integration on Force.com Platform
Integration on Force.com PlatformIntegration on Force.com Platform
Integration on Force.com Platform
Amit Jain
 
Phalcon 2 High Performance APIs - DevWeekPOA 2015
Phalcon 2 High Performance APIs - DevWeekPOA 2015Phalcon 2 High Performance APIs - DevWeekPOA 2015
Phalcon 2 High Performance APIs - DevWeekPOA 2015
Jackson F. de A. Mafra
 
Mini-Training: Let's have a rest
Mini-Training: Let's have a restMini-Training: Let's have a rest
Mini-Training: Let's have a rest
Betclic Everest Group Tech Team
 
Best Practices in Api Design
Best Practices in Api DesignBest Practices in Api Design
Best Practices in Api Design
Muhammad Aamir ...
 
Unit 2
Unit 2Unit 2
Unit 2
Ravi Kumar
 
Business Applications Integration In The Cloud
Business Applications Integration In The CloudBusiness Applications Integration In The Cloud
Business Applications Integration In The Cloud
Anna Brzezińska
 

Similar to Modern REST API design principles and rules.pdf (20)

Rest API Automation with REST Assured
Rest API Automation with REST AssuredRest API Automation with REST Assured
Rest API Automation with REST Assured
 
Overview of Rest Service and ASP.NET WEB API
Overview of Rest Service and ASP.NET WEB APIOverview of Rest Service and ASP.NET WEB API
Overview of Rest Service and ASP.NET WEB API
 
Rest api design
Rest api designRest api design
Rest api design
 
REST and RESTful Services
REST and RESTful ServicesREST and RESTful Services
REST and RESTful Services
 
What are restful web services?
What are restful web services?What are restful web services?
What are restful web services?
 
Restful web-services
Restful web-servicesRestful web-services
Restful web-services
 
REST: So What's It All About? (SAP TechEd 2011, MOB107)
REST: So What's It All About? (SAP TechEd 2011, MOB107)REST: So What's It All About? (SAP TechEd 2011, MOB107)
REST: So What's It All About? (SAP TechEd 2011, MOB107)
 
apidays LIVE Hong Kong 2021 - Multi-Protocol APIs at Scale in Adidas by Jesus...
apidays LIVE Hong Kong 2021 - Multi-Protocol APIs at Scale in Adidas by Jesus...apidays LIVE Hong Kong 2021 - Multi-Protocol APIs at Scale in Adidas by Jesus...
apidays LIVE Hong Kong 2021 - Multi-Protocol APIs at Scale in Adidas by Jesus...
 
ReSTful API Final
ReSTful API FinalReSTful API Final
ReSTful API Final
 
Restful web services by Sreeni Inturi
Restful web services by Sreeni InturiRestful web services by Sreeni Inturi
Restful web services by Sreeni Inturi
 
REST API Recommendations
REST API RecommendationsREST API Recommendations
REST API Recommendations
 
RESTful APIs
RESTful APIsRESTful APIs
RESTful APIs
 
Integration on Force.com Platform
Integration on Force.com PlatformIntegration on Force.com Platform
Integration on Force.com Platform
 
Phalcon 2 High Performance APIs - DevWeekPOA 2015
Phalcon 2 High Performance APIs - DevWeekPOA 2015Phalcon 2 High Performance APIs - DevWeekPOA 2015
Phalcon 2 High Performance APIs - DevWeekPOA 2015
 
Mini-Training: Let's have a rest
Mini-Training: Let's have a restMini-Training: Let's have a rest
Mini-Training: Let's have a rest
 
Best Practices in Api Design
Best Practices in Api DesignBest Practices in Api Design
Best Practices in Api Design
 
Unit 2
Unit 2Unit 2
Unit 2
 
Restful web services
Restful web servicesRestful web services
Restful web services
 
Web services - REST and SOAP
Web services - REST and SOAPWeb services - REST and SOAP
Web services - REST and SOAP
 
Business Applications Integration In The Cloud
Business Applications Integration In The CloudBusiness Applications Integration In The Cloud
Business Applications Integration In The Cloud
 

More from Aparna Sharma

Versioning Best Practices for API Architecture.pdf
Versioning Best Practices for API Architecture.pdfVersioning Best Practices for API Architecture.pdf
Versioning Best Practices for API Architecture.pdf
Aparna Sharma
 
Versioning Best Practices for API Architecture.pdf
Versioning Best Practices for API Architecture.pdfVersioning Best Practices for API Architecture.pdf
Versioning Best Practices for API Architecture.pdf
Aparna Sharma
 
Competitive intelligence with Newsdata.io news API.pdf
Competitive intelligence with Newsdata.io news API.pdfCompetitive intelligence with Newsdata.io news API.pdf
Competitive intelligence with Newsdata.io news API.pdf
Aparna Sharma
 
What is the difference between web scraping and api
What is the difference between web scraping and apiWhat is the difference between web scraping and api
What is the difference between web scraping and api
Aparna Sharma
 
Top 15 news apis in the market in 2022 for you
Top 15 news apis in the market in 2022 for youTop 15 news apis in the market in 2022 for you
Top 15 news apis in the market in 2022 for you
Aparna Sharma
 
What are the different types of web scraping approaches
What are the different types of web scraping approachesWhat are the different types of web scraping approaches
What are the different types of web scraping approaches
Aparna Sharma
 
Top 11 API testing tools for 2022
Top 11 API testing tools for 2022Top 11 API testing tools for 2022
Top 11 API testing tools for 2022
Aparna Sharma
 
Top 11 api testing tools for 2022
Top 11 api testing tools for 2022Top 11 api testing tools for 2022
Top 11 api testing tools for 2022
Aparna Sharma
 
Top api testing tools in 2022
Top api testing tools in 2022Top api testing tools in 2022
Top api testing tools in 2022
Aparna Sharma
 
Is web scraping legal or not?
Is web scraping legal or not?Is web scraping legal or not?
Is web scraping legal or not?
Aparna Sharma
 
Top 17 web scraping tools for data extraction in 2022
Top 17 web scraping tools for data extraction in 2022Top 17 web scraping tools for data extraction in 2022
Top 17 web scraping tools for data extraction in 2022
Aparna Sharma
 
Future of saas in 2022 presentation
Future of saas in 2022 presentationFuture of saas in 2022 presentation
Future of saas in 2022 presentation
Aparna Sharma
 
Future of saas in 2022
Future of saas in 2022Future of saas in 2022
Future of saas in 2022
Aparna Sharma
 
10 best platforms to find free datasets
10 best platforms to find free datasets10 best platforms to find free datasets
10 best platforms to find free datasets
Aparna Sharma
 
Top 13 web scraping tools in 2022
Top 13 web scraping tools in 2022Top 13 web scraping tools in 2022
Top 13 web scraping tools in 2022
Aparna Sharma
 
What is API test automation
What is API test automation What is API test automation
What is API test automation
Aparna Sharma
 
What is the difference between an api and web services
What is the difference between an api and web servicesWhat is the difference between an api and web services
What is the difference between an api and web services
Aparna Sharma
 

More from Aparna Sharma (17)

Versioning Best Practices for API Architecture.pdf
Versioning Best Practices for API Architecture.pdfVersioning Best Practices for API Architecture.pdf
Versioning Best Practices for API Architecture.pdf
 
Versioning Best Practices for API Architecture.pdf
Versioning Best Practices for API Architecture.pdfVersioning Best Practices for API Architecture.pdf
Versioning Best Practices for API Architecture.pdf
 
Competitive intelligence with Newsdata.io news API.pdf
Competitive intelligence with Newsdata.io news API.pdfCompetitive intelligence with Newsdata.io news API.pdf
Competitive intelligence with Newsdata.io news API.pdf
 
What is the difference between web scraping and api
What is the difference between web scraping and apiWhat is the difference between web scraping and api
What is the difference between web scraping and api
 
Top 15 news apis in the market in 2022 for you
Top 15 news apis in the market in 2022 for youTop 15 news apis in the market in 2022 for you
Top 15 news apis in the market in 2022 for you
 
What are the different types of web scraping approaches
What are the different types of web scraping approachesWhat are the different types of web scraping approaches
What are the different types of web scraping approaches
 
Top 11 API testing tools for 2022
Top 11 API testing tools for 2022Top 11 API testing tools for 2022
Top 11 API testing tools for 2022
 
Top 11 api testing tools for 2022
Top 11 api testing tools for 2022Top 11 api testing tools for 2022
Top 11 api testing tools for 2022
 
Top api testing tools in 2022
Top api testing tools in 2022Top api testing tools in 2022
Top api testing tools in 2022
 
Is web scraping legal or not?
Is web scraping legal or not?Is web scraping legal or not?
Is web scraping legal or not?
 
Top 17 web scraping tools for data extraction in 2022
Top 17 web scraping tools for data extraction in 2022Top 17 web scraping tools for data extraction in 2022
Top 17 web scraping tools for data extraction in 2022
 
Future of saas in 2022 presentation
Future of saas in 2022 presentationFuture of saas in 2022 presentation
Future of saas in 2022 presentation
 
Future of saas in 2022
Future of saas in 2022Future of saas in 2022
Future of saas in 2022
 
10 best platforms to find free datasets
10 best platforms to find free datasets10 best platforms to find free datasets
10 best platforms to find free datasets
 
Top 13 web scraping tools in 2022
Top 13 web scraping tools in 2022Top 13 web scraping tools in 2022
Top 13 web scraping tools in 2022
 
What is API test automation
What is API test automation What is API test automation
What is API test automation
 
What is the difference between an api and web services
What is the difference between an api and web servicesWhat is the difference between an api and web services
What is the difference between an api and web services
 

Recently uploaded

Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
Globus
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
Tier1 app
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
informapgpstrackings
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
Globus
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Globus
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
XfilesPro
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
takuyayamamoto1800
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Globus
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
IES VE
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
rickgrimesss22
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
Ortus Solutions, Corp
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
Philip Schwarz
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Shahin Sheidaei
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
abdulrafaychaudhry
 
RISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent EnterpriseRISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent Enterprise
Srikant77
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 

Recently uploaded (20)

Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
 
RISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent EnterpriseRISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent Enterprise
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 

Modern REST API design principles and rules.pdf

  • 1. Modern REST API design principles and rules Typically, when updating or developing an API like Newsdata.io which is a news API for a service to provide news data with quick response time, there are lengthy discussions about the API’s structure, naming, and functions. Although, over time, certain rules have emerged that can be applied to the process and aid in reaching a common ground while developing. Let’s get started with some basics What is an API?
  • 2. API is an abbreviation for Application Programming Interface. It is a software interface that allows two applications to communicate with one another without the need for user intervention. APIs enable a product or service to communicate with other products and services without requiring knowledge of how they are implemented. It facilitates communication between the provider and the client. It is a type of software interface that provides a service to other programs. An API specification is a document or standard that describes how to build or use such a connection or interface. An API is said to be implemented or exposed by a computer system that meets this standard. API can refer to either the specification or the implementation.
  • 3. What is REST? REST was created to work specifically with components such as media components, files, or even objects on a specific hardware device. A RestFul web service is any web service that adheres to the REST principles. For working with the required components, a Restful service would use the standard HTTP verbs GET, POST, PUT, and DELETE. REST is an acronym that stands for Representational State Transfer. • GET — requests a representation of the specified resource. Requests using GET should only retrieve data. • POST — submits data to the specified resource. • PUT — replaces all current representations of the target resource with the request data.
  • 4. • DELETE — deletes the specified resource. • PATCH — applies partial modifications to a resource. When to use REST? When designing web services, one of the most contentious issues is whether REST or SOAP should be used. In the following situations, REST services should be used: • Limited resources and bandwidth — Because SOAP messages are heavier in content and consume far more bandwidth, REST should be used when network bandwidth is limited. • Statelessness — If there is no need to keep information in a consistent state from one request to the next, REST should be used. If you need a proper information flow, where some information from one request needs to flow into another, SOAP is a better choice. We can use any online shopping site as an example. Typically, these sites require the user to first add items that must be purchased to a cart. To complete the purchase, all of the cart items are transferred to the payment page. This is an example of an application that would benefit from the state feature. The cart items’ state must be transferred to the payment page for further processing. • Caching — If a large number of requests must be cached, REST is the ideal solution. Clients may request the same resource multiple times at times. This may result in an increase in the number of requests sent to the server. The most frequently used query results can be saved in an intermediate location by implementing a cache. As a result, whenever a client requests a resource, it will first check the cache. If the resources are available, the process will not proceed to
  • 5. the server. As a result, caching can aid in reducing the number of trips to the web server. • Ease of coding — Coding REST Services and then implementing them is far easier than SOAP. So, if you need a quick win solution for web services, REST is the way to go. REST is the most common API architecture in today’s world (representational state transfer). When using REST, you must adhere to JSON rules and format your requests in invalid JSON. Aside from that, a good API should adhere to the following guidelines: APIs must be separated from the backend, data storage, client, and so on. Because of security and flexibility, it must be a separate layer. State less — different requests should have no knowledge of one another and be processed independently. That also means that each request must include all of the information required for processing. API should function in the same way regardless of whether a client sends a request (e.g. is it a web-server or load-balancer or any other client). REST APIs typically send static resources, but responses can also contain executable code in rare cases (such as Java applets). In these cases, the code should only be executed when needed. Cacheability — Resources should be cacheable on the client or server-side whenever possible. The goal is to improve client-side performance while
  • 6. increasing server-side scalability. However, there are special headers such as Cache-Control that can be used to control the cache behavior. Handle errors and return the appropriate error codes. Instead of throwing an internal error to the user, handle it and send the corresponding code and message (e.g. 404 — not found.) Remember that API should be idempotent (that means that can be invoked many times with the same result). Users can sometimes send duplicate requests to the API. These duplicate requests may have been made inadvertently (or intentionally due to timeout or network issues). As a result, APIs must be fault-tolerant in order for duplicate requests to yield the same results (only POST request is not idempotent). To create documentation for your API, use swagger or another tool. Documentation is a critical component (if someone going to use that API someday) There are also some good manners in naming endpoints as well: • Endpoints should be named with nouns that specify the contents of the resource rather than adding a verb for the function that is being performed (e.g., name endpoint /users and use different HTTP methods for working with the user’s entity rather than creating several endpoints like /get-user, /add-user, etc.). • Use clear names: The name of the endpoint should be clear and intuitive (do not use any shortcuts or abbreviations unless they are
  • 7. obvious — /ids are understandable and preferable to /identification numbers). • Forward slashes are used to create a hierarchy by grouping endpoints into logical groups (/departments/ids and /departments/managers are preferable to /departments-ids and /departments-managers). • Use only lowercase letters: Because URIs are case-sensitive (according to the specification), it is best to avoid using upper case unless absolutely necessary. • Separate words with “-”: different words in the endpoint name are usually separated by “-” rather than underscores or camel case. • Avoid special characters: URLs can only be sent and received using the ASCII character set, so it is possible to use only characters from that set (also there are some expectable but unsafe characters like “ percent ”,”[]”,”{}”,”|”,” “,”<>” and it is better to try to avoid using them as well). The majority of REST APIs are built in conjunction with microservice architecture. In that case, an API structure like this will allow you to change the underlying logic, add or remove components, and so on without changing the communication protocol with other services. What are the challenges in REST API? • Lack of Security — Unlike SOAP, REST does not impose any type of security. This is why REST is ideal for publicly accessible URLs, but when it comes to passing confidential data between the client and the server, REST is the worst mechanism to use for web services.
  • 8. • Lack of state — Most web applications necessitate the use of a stateful mechanism. For example, if you had a purchasing site with a shopping cart mechanism, it is necessary to know the number of items in the shopping cart before the actual purchase is made. Unfortunately, the client bears the burden of maintaining this state, which makes the client application heavier and more difficult to maintain. References 1. https://levelup.gitconnected.com/good-api-design-bad-api-design- 2405dcdde24c 2. https://newsdata.io 3. https://rajat-testprepkart.medium.com/what-are-restful-web-services- 476dd2f99330 4. https://www.guru99.com/comparison-between-web-services.html