/listr-api

Primary LanguageRubyOtherNOASSERTION

General Assembly Logo

listr-api

An API for ember-resources

Installation

  1. [Fork and] clone this repository.
  2. Install dependencies with bundle install.
  3. Create a .env for sensitive settings (touch .env).
  4. Generate new development and test secrets (bundle exec rake secret).
  5. Store them in .env with keys SECRET_KEY_BASE_<DEVELOPMENT|TEST> respectively.
  6. Setup your database with bin/rake db:nuke_pave or bundle exec rake db:nuke_pave.
  7. Run the API server with bin/rails server or bundle exec rails server.

Tasks

Developers should run these often!

  • bin/rake routes lists the endpoints available in your API.
  • bin/rake test runs automated tests.
  • bin/rails console opens a REPL that pre-loads the API.
  • bin/rails db opens your database client and loads the correct database.
  • bin/rails server starts the API.
  • scripts/*.sh run various curl commands to test the API. See below.

API

Lists

Verb URI Pattern Controller#Action
GET /lists lists#index
GET /lists/:id lists#show
POST /lists lists#create
PATCH /lists/:id lists#update
DELETE /lists/:id lists#destroy

GET /lists

Request:

curl --include --request GET http://localhost:3000/lists

Response:

[
  {
    "id": 1,
    "title": "Favorite Things",
    "hidden": false,
    "items": [
      1,
      2,
      3,
      4,
      5
    ]
  },
  {
    "id": 2,
    "title": "Todo",
    "hidden": false,
    "items": [
      6,
      7
    ]
  }
]

GET /lists/:id

Request:

curl --include --request GET http://localhost:3000/lists/$ID

Response:

{
  "id": 1,
  "title": "Favorite Things",
  "hidden": false,
  "items": [
    1,
    2,
    3,
    4,
    5
  ]
}

POST /lists

Request:

curl --include --request POST http://localhost:3000/lists \
  --header "Content-Type: application/json" \
  --data '{
    "list": {
      "title": "Groceries",
      "hidden": false
    }
  }'

Response:

{
  "id": 3,
  "title": "Groceries",
  "hidden": false,
  "items": []
}

PATCH /lists/:id

Request:

curl --include --request PATCH http://localhost:3000/lists/$ID \
  --header "Content-Type: application/json" \
  --data '{
    "list": {
      "hidden": true
    }
  }'

Response:

HTTP/1.1 204 No Content

DELETE /lists/:id

Request:

curl --include --request DELETE http://localhost:3000/lists/$ID

Response:

HTTP/1.1 204 No Content

Items

Verb URI Pattern Controller#Action
GET /lists/:list_id/items items#index
GET /items/:id items#show
POST /lists/:list_id/items items#create
PATCH /items/:id items#update
DELETE /items/:id items#destroy

GET /lists/:list_id/items

Request:

curl --include --request GET "http://localhost:3000/lists/$LIST_ID/items"

Response:

[
  {
    "id": 1,
    "content": "Cats",
    "done": false,
    "list": 1
  },
  {
    "id": 2,
    "content": "Star Wars",
    "done": false,
    "list": 1
  },
  // ...
]

GET /items/:id

Request:

curl --include --request GET http://localhost:3000/items/$ID

Response:

{
  "id": 1,
  "content": "Cats",
  "done": false,
  "list": 1
}

POST /items

Request:

curl --include --request POST http://localhost:3000/items \
  --header "Content-Type: application/json" \
  --data '{
    "item": {
      "content": "Coding",
      "done": false,
      "list_id": 1
    }
  }'

Response:

{
  "id": 8,
  "content": "Coding",
  "done": false,
  "list": 1
}

PATCH /items/:id

Request:

curl --include --request PATCH http://localhost:3000/items/$ID \
  --header "Content-Type: application/json" \
  --data '{
    "item": {
      "done": true,
    }
  }'

Response:

HTTP/1.1 204 No Content

DELETE /items/:id

Request:

curl --include --request DELETE http://localhost:3000/items/$ID

Response:

HTTP/1.1 204 No Content

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:3000/sign-up \
  --header "Content-Type: application/json" \
  --data '{
    "credentials": {
      "email": "an@example.email",
      "password": "an example password",
      "password_confirmation": "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:3000/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:3000/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:3000/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:3000/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:3000/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"
  }
}

Source code distributed under the MIT license. Text and other assets copyright General Assembly, Inc., all rights reserved.