Skip to content
BENIBIX Learn

REST Resource

Development🔌 APIsAPI Design Practices

Also known as Resource (REST), API Resource, Resource URI

One thing a REST API offers, like an order. It has its own address.

Think of it like

Think of it like a drawer with a name on it. Each drawer holds one kind of thing.

Example

Jack's API has /orders for all orders and /orders/42 for one. To cancel order 42, he sends DELETE to /orders/42.

Why it matters

Clear resources make an API easy to guess. Users can work out new endpoints alone.

Definition

A resource is one thing a REST API lets you work with, like a user or an order. Each resource has its own address, such as /orders/42. You use HTTP methods on that address. GET reads it, POST adds one, PUT or PATCH changes it and DELETE removes it. Good resource names are nouns, not verbs.

Example code

http
GET /orders/42 HTTP/1.1
Host: api.example.com
Read one order by asking for its address with GET.
Each resource is a folder with its own address.

Common mistake

Putting verbs in addresses, like /getOrder. The HTTP method already says what to do.

Key takeaways

  1. 1
    Nouns. Name things, not actions.
  2. 2
    One address each. Like /orders/42.
  3. 3
    Methods act. GET, POST, PUT, PATCH, DELETE.

Compare