1

Supposing I have requirements:

  • Register by email
  • Register by social network
  • Login by email
  • Login by social network
  • Logout
  • Get my Profile
  • Edit my Profile
  • Get some user profile
  • List my friends
  • List some user friends
  • Invite friends from social network
  • Add product
  • Edit product
  • Search Product
  • List my products
  • List some user products

How should be endpoints REST API structure?

Alexandru Marculescu
  • 5,569
  • 6
  • 34
  • 50
Sodiaan
  • 341
  • 1
  • 3
  • 10

1 Answers1

1

Always ask yourself:

What are my Resources?

  • Register by email POST /api/registration
  • Register by social network POST /api/providerRegistration
  • Get some user profile GET /api/user?userId={userId}
  • List my friends GET /api/friends
  • List some user friends GET /api/friends?userId={userId}
  • Add product POST /api/product
  • Edit product PUT/PATCH /api/product/{productId}
  • Search Products GET /api/products?status={status}
  • List my products GET /api/products?userId={userId}

And so on - you get the gist of it. Note that the path (REST Resource) is a noun (product), not a verb (search).

Alexandru Marculescu
  • 5,569
  • 6
  • 34
  • 50
  • `GET /api/user?userId={userId}` should be `GET /api/users/{userId}`, `GET /api/friends?userId={userId}` should be `GET /api/users/{userId}/friends` `GET /api/products?userId={userId}`should be `GET /api/users/{userId]/products` – Onurkan Bakırcı Feb 27 '23 at 12:14