0% found this document useful (0 votes)
2 views21 pages

Rest API Design - Course PDF

The document outlines a syllabus for a course on REST API Design, consisting of three modules that cover the fundamentals of APIs, designing RESTful resources and endpoints, and data formats along with API security. It emphasizes the importance of REST principles such as statelessness, client-server architecture, and uniform interfaces, while also providing practical examples and explanations of HTTP request-response cycles. The course aims to equip learners with the knowledge to create robust and scalable RESTful services.

Uploaded by

alterego2683
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views21 pages

Rest API Design - Course PDF

The document outlines a syllabus for a course on REST API Design, consisting of three modules that cover the fundamentals of APIs, designing RESTful resources and endpoints, and data formats along with API security. It emphasizes the importance of REST principles such as statelessness, client-server architecture, and uniform interfaces, while also providing practical examples and explanations of HTTP request-response cycles. The course aims to equip learners with the knowledge to create robust and scalable RESTful services.

Uploaded by

alterego2683
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

REST API Design

Generated by EduGenesis
Built by Prasanna Dolas
Syllabus

Module 1: Understanding REST and APIs - This module introduces the fundamental con-
cepts of Application Programming Interfaces (APIs), the architectural style of REST, and
its core principles.

Module 2: Designing RESTful Resources and Endpoints - This module covers how to
model resources, design intuitive URIs, and effectively use HTTP methods for common
operations.

Module 3: Data Formats, HATEOAS, and API Security - This module explores data repre-
sentation formats like JSON, the concept of HATEOAS for discoverability, and essential
security considerations for REST APIs.
Module 1: Understanding REST and APIs -
This module introduces the fundamental
concepts of Application Programming
Interfaces (APIs), the architectural style of
REST, and its core principles.

Module 1: Understanding REST and APIs


Welcome to the foundational module of our course on REST API Design! In today's intercon-
nected digital world, APIs (Application Programming Interfaces) are the glue that holds every-
thing together. From your favorite mobile apps to complex enterprise systems, APIs enable dif-
ferent software components to communicate and interact seamlessly. Among the various ar-
chitectural styles for designing web APIs, REST (Representational State Transfer) stands out as
the most widely adopted and influential.

In this module, we'll embark on a journey to demystify APIs, understand the core principles of
REST, and lay a solid groundwork for designing robust and scalable RESTful services.

1. What is an API? The Digital Translator

Imagine you walk into a restaurant. You don't go into the kitchen to prepare your meal yourself,
nor do you directly instruct the chef. Instead, you look at a menu, tell the waiter what you want,
and the waiter communicates your order to the kitchen. Once the meal is ready, the waiter
brings it back to you.

In this analogy:

You are the client (the software application requesting a service).

The kitchen is the server (the software system providing the service).
The menu is the API documentation (it tells you what services are available and how to
request them).
The waiter is the API itself (the intermediary that facilitates communication between you
and the kitchen).

Definition: An Application Programming Interface (API) is a set of defined rules that allows
different software applications to communicate with each other. It specifies how software
components should interact, what requests they can make, what data formats they should
use, and what responses they can expect.

Why are APIs Crucial?

APIs are the backbone of modern software development for several reasons:

Interoperability: They enable disparate systems, written in different languages and


running on different platforms, to work together.

Modularity and Reusability: Developers can build complex applications by combining


existing API services, rather than reinventing the wheel.

Innovation: APIs expose functionalities that other developers can use to create new
applications and services, fostering innovation (e.g., social media logins, payment
gateways).

Scalability: By abstracting complex logic behind simple interfaces, APIs can help manage
system growth.

Decoupling: They promote separation of concerns, allowing teams to work independently


on different parts of a system without tightly coupling their codebases.

While there are various types of APIs (library APIs, operating system APIs, etc.), our focus in
this course will be on Web APIs, which allow communication over a network, typically using the
HTTP protocol.

2. Understanding REST: The Architectural Style

Now that we understand what an API is, let's dive into REST. REST stands for Representational
State Transfer. It's not a protocol or a standard; rather, it's an architectural style for design-
ing networked applications. It was first introduced by Roy Fielding in his 2000 doctoral disser-
tation, describing the architectural principles of the World Wide Web itself.

REST defines a set of constraints that, when applied to a system, lead to specific architectural
properties like scalability, simplicity, and reliability. When we say an API is "RESTful," it means it
adheres to these REST principles.
The core idea behind REST is that networked applications should be built like the web: state-
less, client-server based, and centered around resources that can be identified by URLs and
manipulated using standard operations.

3. Core Principles (Constraints) of REST

Fielding outlined several architectural constraints that characterize a RESTful system. Adhering
to these constraints provides the desirable properties of RESTful APIs.

3.1. [VISUALIZE: Client-Server Architecture and Statelessness]

This fundamental constraint dictates a clear separation between the client and the server.

Client: The application that requests and consumes resources (e.g., a web browser, a
mobile app, another server).

Server: The application that provides and manages resources.

Benefits of Client-Server Separation:

Improved Portability: The client can run on various platforms without server-side
changes.

Scalability: Client and server can evolve independently, and servers can be scaled
horizontally without affecting clients.
Enhanced Security: Separation of concerns can lead to better security practices.

Statelessness: This is a critical and often misunderstood constraint. Each request from a
client to a server must contain all the information necessary to understand the request.
The server must not store any client context between requests. Every request is treated as
independent.

Imagine calling a customer service line. If it's stateless, every time you call, you have to explain
your problem from scratch, even if you just spoke to someone five minutes ago. The server
"forgets" who you are or what you were doing after each interaction.

Example: When a client requests a user's profile, the server processes the request based
only on the information sent in that specific request (e.g., user ID). It doesn't rely on any
previous session data stored on the server for that client.

Implications of Statelessness:
Reliability: Easier to recover from failures, as there's no state to lose.

Scalability: Servers don't need to dedicate resources to manage client sessions, making it
easier to distribute requests across multiple servers.

Simplicity: Simplifies server logic.

3.2. Cacheability

Cacheability allows clients and intermediaries (like proxies) to cache responses from the
server. This means that if a client requests the same resource multiple times, it can use a pre-
viously stored response instead of making a new request to the server, reducing server load
and network traffic, and improving performance.

Example: A news article API might include cache-control headers in its response, allowing
a client application to store the article for a certain period before requesting a fresh copy.

3.3. Uniform Interface

This is perhaps the most defining characteristic of REST. It simplifies the overall system archi-
tecture by ensuring that there is a single, consistent way of interacting with resources, regard-
less of their underlying implementation. This constraint has four sub-components:

1. Identification of Resources: Individual resources are identified in requests, for example,


using Uniform Resource Identifiers (URIs).

Example URI: [Link] identifies a specific user.

2. Manipulation of Resources Through Representations: Clients manipulate resources us-


ing "representations" of the resource. When a client requests a resource, the server sends a
representation of that resource (e.g., a JSON or XML document). The client can then modify
this representation and send it back to the server to update the resource.

Example: A client sends a JSON object representing a user's updated name to change
it on the server.

3. Self-descriptive Messages: Each message includes enough information to describe how


to process the message. This often includes using standard HTTP methods (GET, POST, PUT,
DELETE) to indicate the desired action and media types (like application/json ) to de-
scribe the format of the data.
Example: A GET /users/123 request implies "retrieve user 123." The Content-Type:
application/json header in a response indicates the data format.

4. Hypermedia As The Engine Of Application State (HATEOAS): This is a more advanced


concept, but essentially, a client interacts with a REST server entirely through hypermedia
provided dynamically by the server. Instead of having hardcoded URLs, the server provides
links within its responses, guiding the client on what actions are available next. (We will
delve deeper into HATEOAS in Module 3).

3.4. Layered System

In a Layered System, a client cannot ordinarily tell whether it is connected directly to the end
server or to an intermediary along the way. This allows for the introduction of intermediary
servers (like proxies, load balancers, or gateways) to enhance scalability, security, and perfor-
mance without affecting the client or the core server logic.

Example: A client might send a request to a load balancer, which then routes it to one of
many available application servers. The client is unaware of this intermediate step.

4. The HTTP Request-Response Cycle

RESTful APIs primarily leverage the Hypertext Transfer Protocol (HTTP) for communication.
Understanding the basic [VISUALIZE: The HTTP Request-Response Cycle] is crucial.

When you interact with a REST API, your client application sends an HTTP request to a server,
and the server sends back an HTTP response.

4.1. HTTP Request Structure

An HTTP request typically consists of:

Method (or Verb): Indicates the desired action to be performed on the resource.
GET : Retrieve a resource.

POST : Create a new resource.

PUT : Update/replace an existing resource.

PATCH : Partially update an existing resource.

DELETE : Remove a resource.

URI (Uniform Resource Identifier): Identifies the target resource.


Headers: Key-value pairs providing metadata about the request (e.g., Content-Type ,
Authorization , Accept ).

Body (Payload): Optional, contains the data sent to the server (e.g., a JSON object for
creating a new user).

Code Example: A Simple HTTP GET Request (Conceptual curl )

curl -X GET "[Link] \


-H "Accept: application/json"

Explanation:

curl : A command-line tool for making HTTP requests.

-X GET : Specifies the HTTP method as GET, indicating the intention to retrieve a resource.

"[Link] : This is the URI, identifying a product with ID


456 on the [Link] server.
-H "Accept: application/json" : This header tells the server that the client prefers to
receive the response in JSON format.

4.2. HTTP Response Structure

An HTTP response typically consists of:

Status Code: A three-digit number indicating the outcome of the request (e.g., 200 OK ,
404 Not Found , 500 Internal Server Error ).

Headers: Key-value pairs providing metadata about the response (e.g., Content-Type ,
Date , Cache-Control ).

Body (Payload): Optional, contains the requested data or error messages.

Code Example: Corresponding HTTP GET Response (Conceptual)


HTTP/1.1 200 OK
Content-Type: application/json
Cache-Control: max-age=3600
Date: Mon, 01 Jan 2024 12:00:00 GMT
Content-Length: 150

{
"id": "456",
"name": "Super Widget Pro",
"price": 29.99,
"category": "Electronics",
"description": "The latest and greatest widget."
}

Explanation:

HTTP/1.1 200 OK : The status line. 200 is the status code, indicating that the request was
successful. OK is a human-readable reason phrase.

Content-Type: application/json : A header indicating that the response body contains


data in JSON format.

Cache-Control: max-age=3600 : A header suggesting that the client can cache this
response for up to 3600 seconds (1 hour).
Date , Content-Length : Other common response headers providing additional
information.

The JSON block: This is the response body, containing the requested product data.

5. Benefits of RESTful APIs

By adhering to the principles outlined above, RESTful APIs offer significant advantages:

Simplicity: Using standard HTTP methods and URIs makes them intuitive to understand
and use.
Scalability: Statelessness and cacheability make it easier to distribute and scale services.

Flexibility & Portability: Decoupling client and server allows for independent development
and deployment, supporting various client technologies (web, mobile, desktop).

Platform Independence: REST is not tied to any specific programming language or


platform, allowing diverse systems to communicate.
Reliability: Statelessness reduces complexity and aids in recovery from failures.

Conclusion

You've now taken your first major step into the world of REST API design! You understand what
an API is, the core idea behind the REST architectural style, and its fundamental constraints:
Client-Server separation, Statelessness, Cacheability, a Uniform Interface, and a Layered
System. You've also seen how the basic HTTP request-response cycle works.

In the next module, we'll build upon this foundation by exploring how to apply these principles
to design your own RESTful resources and endpoints, focusing on practical URI design and ap-
propriate usage of HTTP methods.

Quiz: Module 1: Understanding REST and APIs - This module introduces


the fundamental concepts of Application Programming Interfaces
(APIs), the architectural style of REST, and its core principles.

Module 1: Understanding REST and APIs - Knowledge Assessment

1. Based on the restaurant analogy used in the lesson, which component accurately repre-
sents the API itself?
A) The client (you)
B) The kitchen (the server)
C) The menu (API documentation)
D) The waiter (the API)

2. Which of the following statements best describes REST as introduced in the module?
A) A mandatory communication protocol for all web services.
B) An architectural style for designing networked applications.
C) A specific programming language used exclusively for backend development.
D) A set of security standards for data encryption.

3. A core principle of RESTful APIs is Statelessness. What does this constraint primarily imply
for a server handling client requests?
A) The server stores client session data to maintain context across multiple requests.
B) Each request from a client must contain all information necessary to understand and
process it, as the server retains no client context.
C) Clients are responsible for maintaining their own state and sending it back to the server
with every request.
D) The server frequently wipes its memory to prevent data accumulation.

4. The "Uniform Interface" constraint in REST includes the sub-component "Self-descriptive


Messages." This means that:
A) All messages must be accompanied by extensive external documentation.
B) Messages should contain enough information, such as HTTP methods and media types,
to indicate how they should be processed.
C) Clients must predict the server's response format without explicit indication.
D) The server dynamically generates message content based on client behavior history.

5. In the conceptual curl example for an HTTP GET request provided in the lesson, what is
the purpose of the -X GET part of the command?
A) It specifies the preferred format (e.g., JSON, XML) for the response data.
B) It defines the Uniform Resource Identifier (URI) of the resource being requested.
C) It indicates the HTTP method (or verb) that describes the action to be performed on the
resource.
D) It sets the maximum cache duration for the response on the client side.

Answer Key

1. D

2. B

3. B

4. B

5. C
Module 2: Designing RESTful Resources and
Endpoints - This module covers how to
model resources, design intuitive URIs, and
effectively use HTTP methods for common
operations.

Module 2: Designing RESTful Resources and Endpoints


Welcome back! In Module 1, we established a solid understanding of what APIs are, why REST
is such a popular architectural style, and its fundamental principles like Client-Server separa-
tion and Statelessness. Now, it's time to get practical. The effectiveness and usability of a REST
API largely depend on how intuitively its resources are defined and how consistently its end-
points are structured.

In this module, we'll dive into the heart of REST API design: learning how to identify and model
the core "things" your API exposes (resources), crafting clear and predictable URLs (URIs) to
access them, and mastering the use of standard HTTP methods to perform common opera-
tions. A well-designed API feels natural to use, almost as if it anticipates the developer's needs.
Let's learn how to build that experience.

1. Understanding and Modeling Resources: The Nouns of Your API

At the core of REST is the concept of a resource. Everything your API interacts with, whether
it's data, an object, or even a service, should be considered a resource. Think of resources as
the "nouns" in your API's language.

What is a Resource?

A resource is any information, data, or concept that can be identified and manipulated by a
client. It's an abstraction of a piece of information or a service that your API offers.

Examples of Resources:
A User: Identified by a unique ID ( /users/123 ).
A Product: Identified by a product code ( /products/P101 ).

An Order: Identified by an order number ( /orders/ORD789 ).

A Comment: Associated with a blog post ( /blog-posts/abc/comments/def ).

A Collection: A group of similar resources (e.g., all users: /users ).

Resource Granularity

One of the first decisions you'll make when modeling resources is their granularity – how large
or small should a resource be?

Too fine-grained: Can lead to "chatty" APIs where clients need to make many requests to
get all necessary information, increasing latency and complexity.
Too coarse-grained: Can lead to "fat" resources that contain too much data, forcing
clients to download unnecessary information and making specific updates difficult.

Best Practice: Aim for resources that represent meaningful business entities. A good rule of
thumb is that if a "thing" has a clear identity, properties, and relationships to other "things," it's
likely a good candidate for a resource.

[VISUALIZE: Resource Modeling Process]

Consider a simple e-commerce application. How do we identify its resources?

1. Start with Use Cases/User Stories:

"As a customer, I want to view products." -> Product resource, Product Collection
resource.

"As a customer, I want to place an order." -> Order resource.

"As a customer, I want to manage my profile." -> User resource.

"As an administrator, I want to manage product categories." -> Category resource.

2. Identify Nouns:

Products, Orders, Users, Categories, Carts, Reviews. These are strong candidates for
resources.

3. Determine Relationships:

A User can have many Orders .


An Order contains many Products (or Order Items ).

A Product belongs to a Category and can have many Reviews .

4. Define Properties:

What data does each resource hold? (e.g., for a Product : id , name , description ,
price , category_id ).

This process helps transform business requirements into a clear set of resources that your API
will expose. Resources are identified by their URIs (Uniform Resource Identifiers), which we'll
explore next.

2. Designing Intuitive URIs (Uniform Resource Identifiers)

A URI is an address that uniquely identifies a resource on the web. In REST, URIs are the pri-
mary mechanism clients use to locate and interact with resources. Well-designed URIs are
critical for an API's usability, discoverability, and maintainability.

Best Practices for URI Design:

1. Use Nouns for Resources, Not Verbs:

URIs should describe what the resource is, not what action to perform on it. HTTP
methods handle the actions.
Bad: /getAllUsers , /createNewProduct , /deleteOrder/123

Good: /users , /products , /orders/123

2. Use Plural Nouns for Collections:

Represent collections of resources with plural nouns.

Good: /users (collection of users), /products (collection of products)

Bad: /user (singular noun for a collection)

3. Reflect Hierarchy for Relationships:

Use path segments to show relationships between resources.

Example: Orders belonging to a specific user.


GET /users/{user_id}/orders (e.g., /users/123/orders )
Example: A specific comment on a specific blog post.
GET /blog-posts/{post_id}/comments/{comment_id} (e.g., /blog-
posts/abc/comments/def )

4. Avoid Trailing Slashes:

While technically /users and /users/ can be different, it's best practice for
consistency to omit trailing slashes.

5. Use Hyphens for Readability:

Separate words in path segments with hyphens for better readability.

Good: /blog-posts

Bad: /blogposts

6. Lowercase Letters:

Maintain consistency by using lowercase letters for all URIs. URIs are case-sensitive.

7. Versioning Your API:

APIs evolve. Versioning allows you to introduce changes without breaking existing
clients. The most common approach is URI-based versioning.

Example:
/api/v1/users

/api/v2/users

Note: While URI versioning is common, some prefer header-based or media-type-


based versioning. For beginners, URI versioning is straightforward.

8. Use Query Parameters for Filtering, Sorting, and Pagination:

When you need to modify a collection resource (e.g., filter, sort, paginate), use query
parameters, not new URI paths. These parameters do not identify new resources but
rather refine the representation of an existing collection.

Example:
GET /products?
category=electronics&min_price=100&sort_by=price,desc&page=2&limit=10

Code Examples of URI Design:


Let's imagine an API for managing a library's books and authors:

Purpose Good URI Bad URI (and why)


Get all books GET /books GET /getAllBooks (uses verb)

Get a specific GET /book?isbn=978-0321765723


GET /books/978-0321765723
book (uses query param for ID)
Create a new POST /books/create (uses verb in
POST /books
book URI)
Get all books by a GET /booksByAuthor?authorId=456
GET /authors/456/books
specific author (less hierarchical, verb-like)
Get books filtered
GET /books? GET /fantasyBooksSortedByTitle
by genre and
genre=fantasy&sort=title,asc (too specific, non-reusable)
sorted
Get the latest
/authors (if future breaking changes
version of authors GET /v1/authors
are expected)
collection

3. Leveraging HTTP Methods for Operations (CRUD)

Once you've identified your resources and designed intuitive URIs, the next step is to define
how clients will interact with those resources. This is where HTTP methods (also known as
HTTP verbs) come into play. These standard verbs communicate the intent of the client's re-
quest to the server, primarily mapping to CRUD (Create, Read, Update, Delete) operations.

[VISUALIZE: HTTP Methods and CRUD Mapping]

Let's break down the most common HTTP methods used in REST APIs:

1. GET - Read (Retrieve)

Purpose: To retrieve a representation of a resource or a collection of resources.

Characteristics:
Safe: Doesn't alter the server's state (it's read-only).

Idempotent: Making the same GET request multiple times will have the same
effect as making it once (you'll always get the same data back, assuming no other
changes).
Usage:
GET /products (Retrieve all products)

GET /products/P101 (Retrieve a specific product)

Code Example: Fetching a product by its ID

curl -X GET "[Link] \


-H "Accept: application/json"

Explanation: This curl command sends a GET request to the specified URI to retrieve
the product P101 . The -H "Accept: application/json" header indicates that the client
prefers the response data in JSON format.

2. POST - Create

Purpose: To create a new resource on the server. Often used to submit data to be
processed.
Characteristics:
Not Safe: Modifies the server's state (creates a new resource).

Not Idempotent: Repeated POST requests to the same URI will typically create
multiple identical resources (e.g., submitting the same form twice might create two
identical entries).

Usage:
POST /users (Create a new user, with user data in the request body)

POST /orders (Create a new order)

Code Example: Creating a new user

curl -X POST "[Link] \


-H "Content-Type: application/json" \
-d '{"username": "johndoe", "email": "john@[Link]"}'

Explanation: This curl command sends a POST request to the /users endpoint. The -
H "Content-Type: application/json" header tells the server that the request body ( -d )
contains data in JSON format. The JSON payload includes the data for the new user.
3. PUT - Update/Replace

Purpose: To completely replace an existing resource with the data provided in the
request body. If the resource does not exist, it can create it (known as an "upsert").

Characteristics:
Not Safe: Modifies the server's state.

Idempotent: Sending the same PUT request multiple times will have the same
outcome as sending it once, because you are always replacing the resource with
the exact same data.

Usage:
PUT /products/P101 (Replace the entire product P101 with the new data)

Code Example: Updating an entire product's details

curl -X PUT "[Link] \


-H "Content-Type: application/json" \
-d '{"id": "P101", "name": "Super Widget v2", "price": 49.99, "description": "An
improved widget."}'

Explanation: This PUT request targets P101 and sends a complete JSON representation
of the product. The server is expected to replace the existing product P101 with this new
data. Note that id is typically included in the body for PUT, even if it's in the URI, to ensure
the client is sending a full, self-contained representation.

4. PATCH - Partial Update

Purpose: To apply partial modifications to an existing resource. Only the fields


specified in the request body are updated; others remain unchanged.

Characteristics:
Not Safe: Modifies the server's state.

Not Necessarily Idempotent: While applying the same patch multiple times might
result in the same final state, it's not strictly guaranteed by the HTTP specification in
the way PUT is.

Usage:
PATCH /users/123 (Update only the email of user 123 )
Code Example: Partially updating a user's email

curl -X PATCH "[Link] \


-H "Content-Type: application/json" \
-d '{"email": "[Link]@[Link]"}'

Explanation: This PATCH request specifically updates only the email field for user 123 ,
leaving other fields like username unchanged.

5. DELETE - Delete

Purpose: To remove a specific resource from the server.

Characteristics:
Not Safe: Modifies the server's state.

Idempotent: Deleting a resource that has already been deleted (or doesn't exist)
should result in the same outcome – the resource is no longer present.

Usage:
DELETE /users/123 (Remove user 123 )

Code Example: Deleting a product

curl -X DELETE "[Link]

Explanation: This DELETE request targets the product P101 to remove it from the sys-
tem. Typically, a successful DELETE request returns a 204 No Content status code, as
there's usually no data to return in the response body.

By consistently applying these HTTP methods, your API becomes predictable and easy to in-
teract with. Clients can understand the intended action just by looking at the method and the
URI.

Conclusion

You've now learned the foundational elements of designing a truly RESTful API! We've covered
how to think about your application's data and functionality as resources, how to craft clean
and intuitive URIs to identify those resources, and how to harness the power of standard HTTP
methods to perform common operations like Create, Read, Update, and Delete.
The principles discussed in this module – using nouns for URIs, pluralizing collections, reflect-
ing hierarchy, and correctly applying HTTP verbs – are crucial for building APIs that are both
powerful and pleasant to work with.

In our next module, we'll expand on these concepts by exploring data representation formats,
the advanced principle of HATEOAS for API discoverability, and essential security considera-
tions for your RESTful services.

Quiz: Module 2: Designing RESTful Resources and Endpoints - This


module covers how to model resources, design intuitive URIs, and
effectively use HTTP methods for common operations.

Module 2: Designing RESTful Resources and Endpoints - Knowledge


Assessment

1. In REST API design, what is the primary definition of a resource?


A) The server's database schema.
B) Any information, data, or concept that can be identified and manipulated by a client.
C) The programming language used to build the API.
D) A user interface component that sends requests.

2. According to the URI design best practices discussed, which of the following is an example
of a well-designed URI for retrieving a list of users?
A) GET /getAllUsers
B) GET /userList
C) GET /users
D) GET /fetchUsers

3. When designing URIs for a REST API, query parameters (e.g., ?key=value ) should primarily
be used for what purpose?
A) To uniquely identify a single specific resource.
B) To specify the action or verb to be performed on a resource.
C) To filter, sort, or paginate a collection of resources.
D) To indicate the API version.

4. The HTTP POST method is used to create new resources. Which statement correctly de-
scribes its safety and idempotency characteristics?
A) It is safe and idempotent.
B) It is safe but not idempotent.
C) It is not safe and not idempotent.
D) It is not safe but is idempotent.

5. Which HTTP method is specifically intended for performing a partial update on an existing
resource, meaning only the fields provided in the request body are modified?
A) PUT
B) POST
C) PATCH
D) DELETE

Answer Key

1. B

2. C

3. C

4. C

5. C

You might also like