fundamental principles of REST API design.pdf
fundamental principles of REST API design.pdf
Fundamental
principle of
REST API
design
@deedev
01
Resource-Based Endpoints:
Clarity Through Nouns
Design your API around resources,
which are the key entities or
objects that your API exposes.
Each resource should have a
unique URI (Uniform Resource
Identifier). The focus should be on
what the API provides access to,
not how to access it.
@deedev
02
Why it Enhances Security and
Clarity:
Predictability: Consistent use of nouns makes
the API easier to understand for developers,
reducing the likelihood of errors in
implementation and potential security
misconfigurations.
Logical Structure: A resource-based approach
naturally maps to your data model (e.g.,
Salesforce SObjects), making it easier to reason
about access controls and permissions. You can
often align your API endpoints with existing
object-level security in Salesforce.
Improved Governance: Clear resource
identification simplifies API management,
monitoring, and the application of security
policies at the resource level.
@deedev
03
Examples
Instead of: /getAccountDetails?
accountId=123 (action-oriented)
Use: /sobjects/Account/123 (resource-
oriented) to retrieve a specific Account
record.
Instead of: /createNewContact
Use: /sobjects/Contact with a POST
request to create a new Contact.
Instead of: /updateOpportunityStage?
opportunityId=456&stageName=Closed
Won
Use: /sobjects/Opportunity/456 with a
PATCH request and the stage in the request
body to update an Opportunity.
@deedev
04
Statelessness:
Independent Requests
Each request from the client to the
server must contain all the
information needed to understand
the request. The server should not
store any client state between
requests. If client state is needed, it
should be managed entirely by the
client (e.g., in cookies or request
parameters).
@deedev
05
Why it Enhances Security and
Clarity:
Reduced Server-Side Complexity: Statelessness
simplifies the server-side implementation, making it
easier to reason about security without worrying
about managing and securing sessions.
Improved Scalability: Stateless servers are easier
to scale horizontally as any server can handle any
request. This inherent scalability contributes to the
overall resilience and availability of your API.
Enhanced Security: By not maintaining session
state on the server, you reduce the risk of session-
based attacks like session hijacking or fixation.
Each request is treated independently and
authenticated/authorized based on the credentials
provided with that specific request (e.g., an OAuth
2.0 access token in the Authorization header).
@deedev
06