Skip to content

sjf125/pokemon-back-end

Repository files navigation

Pokedexter API

An API for serving and storing data for the Pokedexter app. Includes authentication.

Front End Repo

Dependencies

Install with bundle install.

Until Rails 5 is released, this template should follow the most recent released version of Rails 4, as well as track master branches for rails-api and active_model_serializers.

Installation

  1. Download this template.
  2. Setup your database with bin/rake db:nuke_pave or bundle exec rake db:nuke_pave.
  3. Run the API server with bin/rails server or bundle exec rails server.

Structure

This template follows the standard project structure in Rails 4.

curl command scripts are stored in scripts with names that correspond to API actions.

User authentication is built-in.

API

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"
  }
}

Content

Verb URI Pattern Controller#Action
GET /pokedex pokemon#index
GET /pokemon/:id pokemon#show
GET /poketeam poketeam#show
POST /poketeam poketeam#create
PATCH /poketeam poketeam#edit
DELETE /poketeam poketeam#destroy

Pokemon response:

{
  "pokemon": {
    name: "bulbasaur",
    image: "http://pokeapi.co/media/sprites/pokemon/1.png",
    type1: "grass",
    type2: "poison",
    hp: "45",
    attack: "49",
    defense: "49",
    spatk: "65",
    spdef: "65",
    speed: "45",
  }
}

About

An API for serving and storing data for the Pokedexter app

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published