---
# System prepended metadata

title: Sinatra API Checklist

---

# Sinatra API Checklist

## Create

- Send POST request
    - with headers to indicate JSON format
    - a method option set to "POST"
    - and a body containing `JSON.stringified` form data
    - access data in body via `params` in controller route
    - call create on the appropriate class and pass in a hash containing data from params (don't pass params directly)
    - convert the newly created instance to json and return it to the client 

## Read

#### For an index route
- Send a GET request
    - with headers to indicate JSON format
    - Make the appropriate database query to retrieve records
    - convert the collection to json and return it

#### For a show route
- Send of GET request
    - with headers to indicate JSON format
    - include a parameter in the URL (usually the id)
    - find the appropriate record by passing the url parameter to the `.find` method
    - convert the record to json and return it

## Update

- Send a PATCH request
    - with headers to indicate JSON format
    - a method option set to "PATCH"
    - and a body containing the data to update the record with
    - include a parameter in the URL (usually the id)
    - find the appropriate record by passing the url parameter to the `.find` method
    - select the key value pairs within the params hash that are on the list of approved attributes for update
    - call the update method on the found record and pass the approved attributes for update as an argument
    - convert the newly updated record to json and return it

## Delete

- Send a DELETE request
    - with headers to indicate JSON format
    - and a method option set to "DELETE"
    - include a parameter in the URL (usually the id)
    - find the appropriate record by passing the url parameter to the `.find` method
    - call destroy on the record
    - convert the newly deleted record to json and return it (used if we want to enable undo on the frontend)