Resource in REST API Explained with Examples

Published: 2023-02-12
7 min read
Share:

Whenever you call an API endpoint such as /users/123 or /products/45, you're interacting with a resource.

A resource in REST API represents any data, object, or functionality that an API exposes to clients. Common examples include users, products, orders, payments, and customer accounts.

Understanding resources is essential because REST APIs are designed around them. Every request, response, URI, and HTTP method ultimately exists to retrieve, create, update, or delete a resource.

If you're new to REST, start with this guide on What is REST API before diving deeper into resources.

What Is a Resource in REST API?

A resource is a logical representation of something that exists within a system.

For example, in an e-commerce application, resources might include:

  • Users
  • Products
  • Orders
  • Categories
  • Shopping carts

In a social media platform, resources could be:

  • Users
  • Posts
  • Comments
  • Reactions
  • Messages

The resource itself is the concept, while the API provides a way to access and manipulate it through a URI and HTTP methods.

Why Resources Are the Foundation of REST APIs

One reason REST APIs are easy to understand is that they organize everything around resources.

Developers can often predict how an API behaves simply by looking at resource names and URLs.

For example:

/users
/products
/orders

Even without documentation, most developers immediately understand what those endpoints represent.

Well-designed resources make APIs:

  • Easier to learn
  • Easier to maintain
  • More predictable
  • More scalable
  • Consistent across teams

When designing APIs in production systems, choosing resource names early helps avoid future redesigns and compatibility issues.

What Makes Up a Resource in REST API?

A resource in REST API typically consists of several components:

URI (Uniform Resource Identifier)

Every resource must have a unique identifier.

The URI acts as the resource's address and allows clients to locate it.

Examples:

/users
/users/123
/products/987
/orders/5001

To understand how URIs work and how they differ from URLs and URNs, read URL vs URI vs URN.

Resource Representation

Clients do not interact directly with the resource itself.

Instead, they interact with a representation of the resource.

Common formats include:

JSON is the most widely used representation format in modern REST APIs because it is lightweight and easy to parse.

The official MDN JSON documentation provides additional details about JSON structure and usage.

Resource State

The state represents the current data stored within the resource.

For example:

{
  "id": 123,
  "name": "John Doe",
  "email": "john@example.com"
}

If the user's name or email changes, the state of the resource changes as well.

HTTP Methods

Resources are manipulated through HTTP methods.

If you're unfamiliar with how REST relies on HTTP, see How REST API Related to HTTP.

The most commonly used methods are:

  • GET – Retrieve resource data
  • POST – Create a new resource
  • PUT – Replace an existing resource
  • PATCH – Partially update a resource
  • DELETE – Remove a resource

You can learn more about all available HTTP methods in this guide to HTTP Methods in REST API.

Real-World Example of a REST API Resource

Consider a user management system.

The resource:

User

Resource URI:

/users/123

Resource representation:

{
  "id": 123,
  "name": "John Doe",
  "email": "john@example.com"
}

Possible operations:

GET /users/123
PUT /users/123
PATCH /users/123
DELETE /users/123

In this example:

  • The resource is the user
  • The URI identifies the user
  • JSON represents the user data
  • HTTP methods define available actions

This relationship forms the foundation of RESTful API design.

How URIs Identify Resources

A URI should uniquely identify a resource and remain stable over time.

Good REST API URI design follows a few simple principles:

  • Use nouns instead of verbs
  • Use lowercase letters
  • Use hyphens when needed
  • Keep paths concise
  • Maintain consistency

Good examples:

/users
/products
/orders
/customer-reviews

Avoid:

/getUsers
/createProduct
/deleteOrder

The action should be determined by the HTTP method, not embedded in the URI.

The RFC 3986 URI specification defines the standard syntax for URIs used across the web.

Resource Representations: JSON, XML, and HTML

A single resource can have multiple representations.

For example, a client may request:

  • JSON
  • XML
  • HTML

The underlying resource remains the same.

Only the format used to represent that resource changes.

This flexibility allows different applications and systems to consume the same API in ways that best fit their requirements.

To understand how representations are delivered between clients and servers, review the REST API Request and Response Pair guide.

HTTP Methods Used with Resources

HTTP methods define how clients interact with resources.

GET

Retrieves resource information.

Example:

GET /users/123

POST

Creates a new resource.

Example:

POST /users

PUT

Replaces the entire resource.

Example:

PUT /users/123

PATCH

Updates specific fields within a resource.

Example:

PATCH /users/123

DELETE

Removes a resource.

Example:

DELETE /users/123

For method-specific details, see:

Resource vs Endpoint: What's the Difference?

Many developers use these terms interchangeably, but they are not exactly the same.

A resource represents the actual business entity.

Examples:

  • User
  • Product
  • Order

An endpoint is the specific URL where that resource can be accessed.

Example:

Resource: User

Endpoint:
/users/123

Think of the resource as the thing being managed and the endpoint as the address used to reach it.

Common Resource Design Mistakes

Using Verbs Instead of Nouns

Avoid:

/createUser
/deleteProduct
/getOrders

Prefer:

/users
/products
/orders

Exposing Database Structures

Resources should represent business entities, not database implementation details.

Avoid names such as:

/tbl_users
/customer_master

Deeply Nested URLs

Avoid excessive nesting:

/users/123/orders/456/items/789/details

Deep URL structures are harder to maintain and understand.

Inconsistent Naming

Choose a naming convention and stick with it.

For example:

/users
/products
/orders

Avoid mixing styles:

/Users
/product_list
/getOrders

Consistency improves usability and developer experience.

Resource Discovery Within REST APIs

As APIs grow, resource relationships become increasingly important.

REST APIs often expose related resources through links, references, or predictable URI structures.

To learn more about navigating and discovering resources, see Discovery in REST API.

FAQs About Resource in REST API

What is a resource in REST API?

A resource is any object, data entity, or service that an API exposes. Examples include users, products, orders, and customer accounts.

Can a resource have multiple representations?

Yes.

The same resource can be represented in different formats such as JSON, XML, or HTML while still referring to the same underlying data.

What is the difference between a resource and an endpoint?

A resource is the actual entity being managed, while an endpoint is the URI used to access that resource.

Why are URIs important for resources?

URIs provide a unique identifier for every resource, allowing clients to locate and interact with them consistently.

Which HTTP methods are commonly used with resources?

The most common methods are:

  • GET
  • POST
  • PUT
  • PATCH
  • DELETE

Each method performs a specific operation on a resource.

Key Takeaways

  • A resource is the core building block of every REST API.
  • Resources represent business entities such as users, products, and orders.
  • Every resource is identified by a unique URI.
  • Resources can have multiple representations, including JSON and XML.
  • HTTP methods define how clients interact with resources.
  • Good resource design improves API usability, consistency, and maintainability.

Understanding resources is one of the most important steps toward mastering REST API design because nearly every REST principle builds on this concept.

Free Engineering ToolsNEW

8 free, 100% client-side tools for developers — no signup, no data uploads.

Explore all tools