Arad
Arad

Reputation: 12814

Determine appropriate URIs and resources in REST architecture

I'm relatively new to REST architecture, I have some question about how I should implement my RESTful API for my project.

What URIs and resources would be appropriate for:

1. Login and logout?

What I guess: POST or DELETE /api/users/auth or POST or DELETE /api/users/login?

2. Set, delete, or get user's avatar?

What I guess: POST or DELETE or GET /api/users/{id}/avatar. is it correct?

3. Verify by the sent code?

What I guess: POST /api/users/{id}/verification. is it correct?

4. Change a single or some specific properties of the user? (e.g. changing email or username)

What I guess: PACTH /api/users/{id} or PUT /api/users/{id}/email. is it correct?

Thanks in advance.

Upvotes: 1

Views: 37

Answers (1)

Roman Marusyk
Roman Marusyk

Reputation: 24609

1. Login and logout?

For web API you have to implement OAuth Authorization and then use

POST /oauth to get token

2. Set, delete, or get user's avatar?

There are no specific rules for that but humans SHOULD be able to easily read and construct URLs. So, I think it will be ok

POST or DELETE or GET /api/users/{id}/avatar

3. Verify by the sent code?

It's up to you.

4. Change a single or some specific properties of the user? (e.g. changing email or username)

Here I suggest to use PACTH /api/users/{id} with json body to partly update or PUT /api/users/{id} to full update user. Look at this package

You can read Microsoft REST API Guidelines to more details.

Upvotes: 1

Related Questions