Devonte202 / problem-set-7_3

Problem Set 7.3 - RESTful API Design

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unit 7 Problem Set #3

Schema Design and Building RESTful APIs

Directions

  1. Fork and clone this lab.
  2. Answer the following questions directly in this README. Be sure that your answers are well-formatted.
  3. For the final question (build a to-do list), create all of your necessary app files in this directory. (I have included GitHub's standard Node.js .gitignore template so that you don't end up pushing node_modules to GitHub.

  1. What are the four types of HTTP requests that correspond to creating, reading, updating, and deleting resources? Why is it important to use these different types of requests?

The four http requests that correspond CRUD are these respectively. POST, GET, PUT, DELETE. It's important to use these requests so that you can create a stateful experience between your client side and server side. If your client creates a resource and that resource is not created and saved on the server side, the the application is essentially static, with the same assets and resources on each load. Saving, editing, or deleting corresponding data between client and server is integral to stateful applications.

  1. You've recently learned about an API for a cat sitting company. The API is fully RESTful for a resource called cats. You also happen to know that their database is running Postgresql on the backend. What are the five types of requests the API will respond to? Based on the description, list the HTTP method, the path, and what SQL the request will fire.
http method path sql description
POST /add-cat INSERT INTO cats (cols.) VALUES (vals.) Creating a cat
GET /get-cats SELECT * FROM cats Retrieving all the cats
GET /get-cat/:id SELECT * FROM cats WHERE id = $1 Retriving a specific cat
PUT /edit-cat/:id UPDATE cats SET col = new val WHERE col = old val Updating a specific cat
DELETE /delete-cat/:id DELETE FROM cats Where col = val Deleting a cat

  1. You're working on a blogging application and doing some debugging. You see in the logs that the following SQL has fired:

    SELECT * FROM articles WHERE id = 9;

    Given that the application is RESTful, what HTTP method and request would you expect to have been made to fire that SQL?


The SQL query above is made to select all the properties of an article with an id of 9. Therefore the request that must have been made is a GET request with path of /article/9.

  1. You've been hired to do some work for Discogs, an application to help users track a vinyl record collection. A Collection has many Albums, and an Album has many collections via a join table called Ownership. You've been asked to build a feature that allows to remove an album from their collection. What HTTP Method/URL/controller action would you use to implement this feature?

I would first build out the controller method which would contain my SQL query that deletes the album from the database.The mentioned SQL query would leverage the exitence of correlated Foreign keys on the Ownership table. The method I create would then be invoked upon the server recieving a DELETE request at the url /delete-album/:id. Or something in that realm.

  1. Choose your favorite web application. What's an example of a one-to-many and many-to-many relationship that might exist within the app?

One of my favorite apps is Instagram. I believe a great example of a one-to-many relationship would be the relationship between a post a tagged users. An example of a many-to-many relationship would be the relationship between users and mutual followers.

  1. Build a full CRUD, RESTful API using Express for a Todo List. A TodoList should have many items and belong to a user. Each endpoint should respond with the appropriate JSON response. Our API should support:
    • An index route to see a list of todos.
    • A show route to see details about an individual todo item.
    • The ability to update a todo (i.e. mark complete)
    • Delete a todo item
    • Create a Todo list item

PATHS

http method path description
GET / Greets the user
GET /incomplete-tasks Gets incomplete tasks
GET /completed-tasks Gets complete tasks
GET /tasks Gets all tasks
POST /add-task Adds task
DELETE /delete-task/:id Deletes a specific task
PUT /update-task/:id Updates a specific task
PUT /complete-task/:id Completes a specific task

Deploy Your Project to Heroku and include a link here: Link to API

Documentation

Get all tasks for a specific user

Send a GET request to the path /tasks.

Get all incomplete tasks for a specific user

Send a GET request to the path /incomplete-tasks.

Get all completed tasks for a specific user

Send a GET request to the path /complete-tasks.

For all GET requests, include the user's user_id in the body of the request like such:

{
   user_id: {USER'S ID HERE}
}

Add a new task to a user's to do list.

Send a POST request to the path /add-task. In the body of the request include the following data as JSON:

{
   user_id: {USER'S ID HERE},
   name: {NAME OF THE NEW TASK HERE},
   description: {DESCRIPTION OF TASK}
}

Delete a task from a user's to do list

Send a DELETE request to the path /delete-task/{TASK_ID HERE}

Change a task's name or description on a user's to do list

Send a PUT request to the path /update-task/{TASK_ID HERE}. Include the new name and description in the body of the request.

{
   name: {NAME OF THE NEW TASK HERE},
   description: {DESCRIPTION OF TASK}
}

Mark a task as completed

Send a PUT request to the path /complete-task/{TASK_ID HERE}.

About

Problem Set 7.3 - RESTful API Design


Languages

Language:JavaScript 100.0%