Anindya Dhruba
Anindya Dhruba

Reputation: 500

Desiging restful API for user resource

I am designing a restful API by using Laravel & AngularJS. I know the basic of restful API, but having trouble to figure out what will be the best way to design it for user resource.

Let's guess, user can have his profile & can update profile. So, the URL should be something like this:

  1. For User Profile View: www.example.com/users/{id}
  2. For User Profile Update: www.example.com/users/{id}/edit

but these URLs look bad. The pretty URLs are:

  1. For User Profile View: www.example.com/profile
  2. For User Profile Update: www.example.com/profile/edit

OR

  1. For User Profile View: www.example.com/{username}
  2. For User Profile Update: www.example.com/{username}/edit

My question is, if I use the last two pretty URLs, will it break the restful API principle? And which is the most appropriate way of designing API for user resource?

Upvotes: 0

Views: 349

Answers (1)

AboElzooz
AboElzooz

Reputation: 319

I think you should get the advantage of using HTTP verbs in RESTFUL api's which would make your url's more readable such:

`GET www.example.com/users/{id}` for profile retrieval
`PUT www.example.com/users/{id}` for profile update

You can review this blog for more information HTTP Verbs

Upvotes: 2

Related Questions