0
0
Rest APIprogramming~5 mins

Noun-based resource naming in Rest API

Choose your learning style9 modes available
Introduction

We use noun-based names for resources in APIs to clearly show what data or thing we are working with. It makes the API easy to understand and use.

When creating an API to manage users, use nouns like 'users' to represent user data.
When building an API for a blog, use nouns like 'posts' and 'comments' to name resources.
When designing an API for a store, use nouns like 'products' and 'orders' to represent items and purchases.
Syntax
Rest API
/resource
/resource/{id}
/resource/{id}/subresource

Use plural nouns for resource names (e.g., 'users', 'products').

Use path parameters (like {id}) to specify a single resource item.

Examples
'/users' refers to all users, '/users/123' refers to the user with ID 123.
Rest API
/users
/users/123
'/products' is the list of products, '/products/456/reviews' is the reviews for product 456.
Rest API
/products
/products/456/reviews
Sample Program

This shows common HTTP methods with noun-based resource naming for a 'books' resource.

Rest API
GET /books
GET /books/10
POST /books
PUT /books/10
DELETE /books/10
OutputSuccess
Important Notes

Always use nouns, not verbs, for resource names to keep APIs consistent.

Use plural form for collections to clearly indicate multiple items.

Use HTTP methods (GET, POST, PUT, DELETE) to define actions on resources.

Summary

Noun-based naming makes APIs clear and easy to use.

Use plural nouns for resource paths.

Use HTTP methods to perform actions on these noun resources.