Given User
and Tweet
models, how would you structure RESTful urls for the following information:
-
a list of a given user's tweets
-
a list of a given user's followers
-
a list of a given user's feed (a combination of multiple users)
What would backend methods (you can use pseudocode) look like for each of these?
What can be made more RESTful about these URLs?
www.app.com/api/createuser + POST + { username: "Person", age: 33 } => creates a new user
www.phonebook.com/api/addresses/ + POST + { areaCode: 54321 } => returns a list of addresses in that area code
www.apartments.com/api/cities/53/apartments/ + POST + { id: 3 } => removes apartment 3 from the city with ID 53
Given these URLs, try and unpack them into their own models:
www.states.com/api/states/11/regions/
www.states.com/api/states/3/regions/5/districts/
www.states.com/api/states/44/regions/2/districts/9/counties
4. What REST principle(s) are violated by this request cycle?
www.myapp.com/users/6/articles?id=88 + GET
[HttpGet]
[Route("/api/users/{userId}/articles")]
public void DeleteUserArticle(int userId)
{
int articleId = int.Parse(Request.GetQueryKeyValuePairs()["id"]);
repo.DeleteArticleFromUser(userId, articleId);
}