Skip to content

Instantly share code, notes, and snippets.

@BlaiseGratton
Last active November 8, 2016 01:02
Show Gist options
  • Save BlaiseGratton/2493622fc9bb3595fb185d1acbd74e3b to your computer and use it in GitHub Desktop.
Save BlaiseGratton/2493622fc9bb3595fb185d1acbd74e3b to your computer and use it in GitHub Desktop.

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/

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);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment