Skip to content

danielleletarte/curate-api

Repository files navigation

General Assembly Logo

curate-api

Find the repo for the curate. front end client here.

Find the deployed curate. front end client here.

Entity Relationship Diagram

A copy of the ERD can be found here.

API

This API helps users with an interest in vegan and sustainable fashion manage keep track of their favorite sources. A user can create create retail profiles, track whether the retailer independent and whether they follow vegan, slow, or sustainable practices. A user can also track any important notes they want to remember about the retailer.

Authentication

Verb URI Pattern Controller#Action
POST /sign-up users#signup
POST /sign-in users#signin
PATCH /change-password/:id users#changepw
DELETE /sign-out/:id users#signout

POST /sign-up

Request:

curl --include --request POST http://localhost:4741/sign-up \
  --header "Content-Type: application/json" \
  --data '{
    "credentials": {
      "email": "an@example.email",
      "password": "an example password"
    }
  }'
scripts/sign-up.sh

Response:

HTTP/1.1 201 Created
Content-Type: application/json; charset=utf-8

{
  "user": {
    "id": 1,
    "email": "an@example.email"
  }
}

POST /sign-in

Request:

curl --include --request POST http://localhost:4741/sign-in \
  --header "Content-Type: application/json" \
  --data '{
    "credentials": {
      "email": "an@example.email",
      "password": "an example password"
    }
  }'
scripts/sign-in.sh

Response:

HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8

{
  "user": {
    "id": 1,
    "email": "an@example.email",
    "token": "33ad6372f795694b333ec5f329ebeaaa"
  }
}

PATCH /change-password/:id

Request:

curl --include --request PATCH http://localhost:4741/change-password/$ID \
  --header "Authorization: Token token=$TOKEN" \
  --header "Content-Type: application/json" \
  --data '{
    "passwords": {
      "old": "an example password",
      "new": "super sekrit"
    }
  }'
ID=1 TOKEN=33ad6372f795694b333ec5f329ebeaaa scripts/change-password.sh

Response:

HTTP/1.1 204 No Content

DELETE /sign-out/:id

Request:

curl --include --request DELETE http://localhost:4741/sign-out/$ID \
  --header "Authorization: Token token=$TOKEN"
ID=1 TOKEN=33ad6372f795694b333ec5f329ebeaaa scripts/sign-out.sh

Response:

HTTP/1.1 204 No Content

Users

Verb URI Pattern Controller#Action
GET /users users#index
GET /users/1 users#show

GET /users

Request:

curl --include --request GET http://localhost:4741/users \
  --header "Authorization: Token token=$TOKEN"
TOKEN=33ad6372f795694b333ec5f329ebeaaa scripts/users.sh

Response:

HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8

{
  "users": [
    {
      "id": 2,
      "email": "another@example.email"
    },
    {
      "id": 1,
      "email": "an@example.email"
    }
  ]
}

GET /users/:id

Request:

curl --include --request GET http://localhost:4741/users/$ID \
  --header "Authorization: Token token=$TOKEN"
ID=2 TOKEN=33ad6372f795694b333ec5f329ebeaaa scripts/user.sh

Response:

HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8

{
  "user": {
    "id": 2,
    "email": "another@example.email"
  }
}

User Actions

index /retailprofiles

The index action is a GET that retrieves all the retail profiles associated with a user. The response body will contain JSON containing an array of retail profiles, e.g.:

Request:

API="http://localhost:4741"
URL_PATH="/retailprofiles"

curl "${API}${URL_PATH}" \
  --include \
  --request GET \
  --header "Authorization: Token token=${TOKEN}" \
TOKEN="aqPhrVctPxX+kg21ColVUMoNYxfIhA79zVJQq5ZqCsE=--1Mw119XiPrAMD9dpArKrcXJqGMlcy6g5uBraKNtFf5s="

Response:

HTTP/1.1 201 Created
Content-Type: application/json; charset=utf-8

{
  "retailprofiles": [
  {
    "id": 1,
    "name": "this is a test",
    "siteUrl": "www.test.com",
    "notes": "cool shop",
    "vegan": true,
    "slow:" false,
    "sustainable": true,
    "independent": true
  }
  {
    "id": 2,
    "name": "this is a test",
    "siteUrl": "www.test.com",
    "notes": "cool shop",
    "vegan": true,
    "slow:" false,
    "sustainable": true,
    "independent": true
  }
 ]
}

show /retailprofiles/:id

The show action is a GET specifing the id of the retail profile to retrieve. If the request is successful the status will be 200, OK, and the response body will contain JSON for the idea requested.

Request:

API="${API_ORIGIN:-http://localhost:4741}"
URL_PATH="/retailprofiles/$ID"
curl "${API}${URL_PATH}" \
  --include \
  --request GET \
  --header "Authorization: Token token=$TOKEN" \
  --header "Content-Type: application/json"
ID=2 TOKEN=BAhJIiVlODkyNTczNzYzYmVkN2RmOWNlYWM1MjAyZDhmMDI2NgY6BkVG--23303c36d71984539b1c7c76dd96acaeb37c437c

Response:

HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8

{
  "retailprofile": {
    "id": 2,
    "name": "this is a test",
    "siteUrl": "www.test.com",
    "notes": "cool shop",
    "vegan": true,
    "slow:" false,
    "sustainable": true,
    "independent": true
  }
}

create /retailprofiles

The create action expects a POST with an empty body (e.g '' or '{}' if JSON). If the request is successful, the response will have an HTTP Status of 201 Created, and the body will contain JSON of the created retail profile set to the associated user.

Request:

API="${API_ORIGIN:-http://localhost:4741}"
URL_PATH="/retailprofiles"
curl "${API}${URL_PATH}" \
  --include \
  --request POST \
  --header "Content-Type: application/json" \
  --header "Authorization: Token token=$TOKEN" \
  --data '{
    "retailprofile": {
      "name": "'"${NAME}"'",
      "siteUrl": "'"${URL}"'",
      "vegan": "'"${VEGAN}"'",
      "sustainable": "'"${SUSTAINABLE}"'",
      "slow": "'"${SLOW}"'",
      "independent": "'"${INDEPENDENT}"'",
      "notes": "'"${NOTES}"'"
    }
  }'
TOKEN="dz6YduYcdHpBIqG8uai9xUXIYNoZV1x6oxFhlileaPg=--NC2w1h0YMcb9B5H1oRwviehzw4a7AkXpVeiL0R2PzwA="
NAME="Moo Shoes is vegan"
URL="https://mooshoes.com/"
VEGAN="true"
SUSTAINABLE="true"
SLOW="true"
INDEPENDENT="true"
NOTES="shoes!"

Response:

HTTP/1.1 201 Created
Content-Type: application/json; charset=utf-8

{
  "retailprofile": {
    "id": 2,
    "name": "this is a test",
    "siteUrl": "www.test.com",
    "notes": "cool shop",
    "vegan": true,
    "slow:" false,
    "sustainable": true,
    "independent": true
  }
}

update /retailprofiles/:id

This update action expects an empty (e.g '' or '{}' if JSON) PATCH to an existing idea.

If the request is successful, the response will have an HTTP Status of 200 OK, and the body will be JSON containing the updated retail profile.

Request:

API="${API_ORIGIN:-http://localhost:4741}"
URL_PATH="/retailprofiles/$ID"
curl "${API}${URL_PATH}/${ID}" \
  --include \
  --request PATCH \
  --header "Content-Type: application/json" \
  --header "Authorization: Token token=${TOKEN}" \
  --data '{
    "retailprofile": {
      "name": "'"${NAME}"'",
      "siteUrl": "'"${URL}"'",
      "vegan": "'"${VEGAN}"'",
      "sustainable": "'"${SUSTAINABLE}"'",
      "slow": "'"${SLOW}"'",
      "independent": "'"${INDEPENDENT}"'",
      "notes": "'"${NOTES}"'"
    }
  }'
TOKEN="dz6YduYcdHpBIqG8uai9xUXIYNoZV1x6oxFhlileaPg=--NC2w1h0YMcb9B5H1oRwviehzw4a7AkXpVeiL0R2PzwA="
NAME=""
URL="https://mooshoes.com/"
VEGAN="true"
SUSTAINABLE="true"
SLOW="true"
INDEPENDENT="true"
NOTES="shoes!"

Response:

HTTP/1.1 204 No Content

destroy /retailprofiles/:id

The destroy action is a DELETE request specifing the id of the retail profile to delete. If the request is successful the status will be 204 No Content.

Request:

API="http://localhost:4741"
URL_PATH="/retailprofiles"

curl "${API}${URL_PATH}/${ID}" \
  --include \
  --request DELETE \
  --header "Authorization: Token token=$TOKEN"
TOKEN="VmGwZbqcEzjeZdKeUBSSiCPIemDPB4VVZcAWa533en0=--Ptjjc2iypOpWwhJZgDJOywrG1cJl3UmJZQAa9L0jrRw="
ID="592f1ca4c8a425eda5173fcc"

Response:

HTTP/1.1 204 No Content
  1. All content is licensed under a CC­BY­NC­SA 4.0 license.
  2. All software code is licensed under GNU GPLv3. For commercial use or alternative licensing, please contact legal@ga.co.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published