Rest method, link with what we return
up vote
0
down vote
favorite
I've read all best practices about Restfull API but they always use simple examples. I often read things like :
GET /cars -> return all cars
PUT /cars/1 -> update car with id 1
etc...
So ok, we name the rest method "cars" because we're dealing with car resources.
But what about "advanced operations" ?
For example, I have a system where users have accounts. I want to create a GET method that allows to check if a person is linked to an account existing in database.
So I can create :
GET /users/1/10 -> return users data if user with id 1 is linked to the account with id 10
Is it good to name "/users" my method ? Knowing that the purpose to my method is not really to get user data but check if his account exists in databse
In other words, do we have to name our Rest methods depending on the data we return or depending on the purpose of the method ?
rest restful-url
add a comment |
up vote
0
down vote
favorite
I've read all best practices about Restfull API but they always use simple examples. I often read things like :
GET /cars -> return all cars
PUT /cars/1 -> update car with id 1
etc...
So ok, we name the rest method "cars" because we're dealing with car resources.
But what about "advanced operations" ?
For example, I have a system where users have accounts. I want to create a GET method that allows to check if a person is linked to an account existing in database.
So I can create :
GET /users/1/10 -> return users data if user with id 1 is linked to the account with id 10
Is it good to name "/users" my method ? Knowing that the purpose to my method is not really to get user data but check if his account exists in databse
In other words, do we have to name our Rest methods depending on the data we return or depending on the purpose of the method ?
rest restful-url
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I've read all best practices about Restfull API but they always use simple examples. I often read things like :
GET /cars -> return all cars
PUT /cars/1 -> update car with id 1
etc...
So ok, we name the rest method "cars" because we're dealing with car resources.
But what about "advanced operations" ?
For example, I have a system where users have accounts. I want to create a GET method that allows to check if a person is linked to an account existing in database.
So I can create :
GET /users/1/10 -> return users data if user with id 1 is linked to the account with id 10
Is it good to name "/users" my method ? Knowing that the purpose to my method is not really to get user data but check if his account exists in databse
In other words, do we have to name our Rest methods depending on the data we return or depending on the purpose of the method ?
rest restful-url
I've read all best practices about Restfull API but they always use simple examples. I often read things like :
GET /cars -> return all cars
PUT /cars/1 -> update car with id 1
etc...
So ok, we name the rest method "cars" because we're dealing with car resources.
But what about "advanced operations" ?
For example, I have a system where users have accounts. I want to create a GET method that allows to check if a person is linked to an account existing in database.
So I can create :
GET /users/1/10 -> return users data if user with id 1 is linked to the account with id 10
Is it good to name "/users" my method ? Knowing that the purpose to my method is not really to get user data but check if his account exists in databse
In other words, do we have to name our Rest methods depending on the data we return or depending on the purpose of the method ?
rest restful-url
rest restful-url
asked 23 hours ago
whySoSerious
405
405
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
- if one user has more than one account and if you use two collections for users and accounts then route should be as follows to access a specific resource.
/users/{userId}/accounts/{accountID}.
You always need to maintain the relationship between resources. In this case, an account is a sub-resource of a user.
- Or you can use filtering as follows
/users/{userId}/accounts?accountId=10
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
- if one user has more than one account and if you use two collections for users and accounts then route should be as follows to access a specific resource.
/users/{userId}/accounts/{accountID}.
You always need to maintain the relationship between resources. In this case, an account is a sub-resource of a user.
- Or you can use filtering as follows
/users/{userId}/accounts?accountId=10
add a comment |
up vote
0
down vote
- if one user has more than one account and if you use two collections for users and accounts then route should be as follows to access a specific resource.
/users/{userId}/accounts/{accountID}.
You always need to maintain the relationship between resources. In this case, an account is a sub-resource of a user.
- Or you can use filtering as follows
/users/{userId}/accounts?accountId=10
add a comment |
up vote
0
down vote
up vote
0
down vote
- if one user has more than one account and if you use two collections for users and accounts then route should be as follows to access a specific resource.
/users/{userId}/accounts/{accountID}.
You always need to maintain the relationship between resources. In this case, an account is a sub-resource of a user.
- Or you can use filtering as follows
/users/{userId}/accounts?accountId=10
- if one user has more than one account and if you use two collections for users and accounts then route should be as follows to access a specific resource.
/users/{userId}/accounts/{accountID}.
You always need to maintain the relationship between resources. In this case, an account is a sub-resource of a user.
- Or you can use filtering as follows
/users/{userId}/accounts?accountId=10
answered 20 hours ago
Janaka
361
361
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53371110%2frest-method-link-with-what-we-return%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown