简体   繁体   中英

Rest endpoints structure

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?

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 ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM