Skip to content

API Documentation

Sebastian Zapata Mardini edited this page May 17, 2020 · 2 revisions

This page describes the Crown Tracker REST API

Hosts

  • Development: http://localhost:3000/api/v1/
  • Production: TBD

Authentication

Crown Tracker's API provides a JWT mechanism for authentication. Requests should contain an Authorization header with a valid user JSON Web Token, something like:

Authorization: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c"

Endpoints

Endpoint VERB Description Requires authentication?
api/v1/users POST Create a new regular user No
api/v1/users/profile GET Get user profile by JWT Yes
api/v1/users/api/v1/sessions POST Create a new session No
api/v1/users/api/v1/incidents POST Create a new incident Yes
api/v1/users/api/v1/incidents/:id GET Get an incident by id Yes
api/v1/users/api/v1/incidents GET Get all the existing incidents No

Create User

  • URL: http://localhost:3000/api/v1/users
  • Verb: POST
  • Require authentication?: No

Create a new regular user.

Body:

{
  "name": "Hector",
  "last_name": "lavoe", 
  "email": "[email protected]", 
  "username": "hector-lavoe", 
  "password": "la-fania",
  "password_confirmation": "la-fania"
}

Response:

{
  "user": {
    "id": 17,
    "name": "Hector",
    "last_name": "lavoe",
    "email": "[email protected]",
    "username": "hector-lavoe",
    "password_digest": "$2a$12$/pLlHGK2yyWUGEcQVTZO/.t18v3K/tLUVS7oBbnxfKitzhQ/LPfXq",
    "admin": false,
    "status": "active",
    "validator": false,
    "organization": false,
    "created_at": "2020-05-17T20:59:12.377Z",
    "updated_at": "2020-05-17T20:59:12.377Z"
  },
  "token": "eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoxNywiZXhwIjoxNTg5ODM1NTUyfQ.XptqrR_M4OtN6umxN0RbbTQMjCmVjbAmSTVOV4V4SU0"
}

User Profile

  • URL: http://localhost:3000/api/v1/users/profile
  • Verb: POST
  • Require authentication?: No

Response:

{
  "id": 9,
  "name": "Marco",
  "last_name": "Polo",
  "email": "[email protected]",
  "username": "marco-polo",
  "password_digest": "$2a$12$j536XjYJlGDjlAfSZgORjO3a9/CAMpTHLt7hGyrBd1eRfgQ.Gg4m2",
  "admin": true,
  "status": "active",
  "validator": false,
  "organization": false,
  "created_at": "2020-05-16T22:11:54.892Z",
  "updated_at": "2020-05-16T22:11:54.892Z"
}

Create Session

  • URL: http://localhost:3000/api/v1/sessions/
  • Verb: POST
  • Require authentication?: No

Body:

{
  "identifier": "marco-polo",
  "password": "crown-tracker"
}

Response:

{
  "token": "eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjo5LCJleHAiOjE1ODk4MzEwMzd9.aQgERuJ2v07FY_-1p72LZIItfJmTLh9zSQl8LWogi64",
  "expiration_time": "18-05-2020 19:43",
  "username": "marco-polo"
}

Create Incident

  • URL: http://localhost:3000/api/v1/incidents
  • Verb: POST
  • Require authentication?: Yes

Create a new incident.

Body:

{
  "address": "Carrera 76 #53 - 89",
  "description": "Lorem Ipsum is simply dummy text of the printing and typesetting industry.",
  "age": 92,
  "gender": null,
  "status": "dead",
  "latitude": 6.262362,
  "longitude": -75.565826
}

Response:

{
    "id": 11,
    "address": "Carrera 76 #53 - 89",
    "description": "Lorem Ipsum is simply dummy text of the printing and typesetting industry.",
    "age": 92,
    "gender": "male",
    "status": "dead",
    "latitude": 6.262362,
    "longitude": -75.565826,
    "confirmed": false,
    "created_at": "2020-05-17T21:15:35.890Z",
    "updated_at": "2020-05-17T21:15:35.890Z",
    "archived": false,
    "user_id": 9
}

Get Incident

  • URL: http://localhost:3000/api/v1/incidents/:id
  • Verb: GET
  • Require authentication?: Yes

Get an incident by id.

Response:

{
{
  "id": 11,
  "address": "Carrera 76 #53 - 89",
  "description": "Lorem Ipsum is simply dummy text of the printing and typesetting industry.",
  "age": 92,
  "gender": "male",
  "status": "dead",
  "latitude": 6.262362,
  "longitude": -75.565826,
  "confirmed": false,
  "created_at": "2020-05-17T21:15:35.890Z",
  "updated_at": "2020-05-17T21:15:35.890Z",
  "archived": false,
  "user_id": 9
}

Get All Incidents

  • URL: http://localhost:3000/api/v1/incidents
  • Verb: GET
  • Require authentication?: No

Get all the existing incidents.

Response:

[
  {
    "id": 12,
    "address": "Carrera 76 #53 - 89",
    "description": "Lorem Ipsum is simply dummy text of the printing and typesetting industry.",
    "age": 34,
    "gender": "female",
    "status": "dead",
    "latitude": 6.262362,
    "longitude": -75.565826,
    "confirmed": true,
    "created_at": "2020-05-17T21:18:18.503Z",
    "updated_at": "2020-05-17T21:18:18.503Z",
    "archived": false,
    "user_id": 23
  },
  {
    "id": 13,
    "address": "Carrera 76 #53 - 89",
    "description": "Lorem Ipsum is simply dummy text of the printing and typesetting industry.",
    "age": 20,
    "gender": "female",
    "status": "recovered",
    "latitude": 6.26297,
    "longitude": -75.557296,
    "confirmed": true,
    "created_at": "2020-05-17T21:18:18.508Z",
    "updated_at": "2020-05-17T21:18:18.508Z",
    "archived": false,
    "user_id": 23
  },
  {
    "id": 14,
    "address": "Carrera 76 #53 - 89",
    "description": "Lorem Ipsum is simply dummy text of the printing and typesetting industry.",
    "age": 81,
    "gender": "female",
    "status": "suspicious",
    "latitude": 6.272952,
    "longitude": -75.585106,
    "confirmed": false,
    "created_at": "2020-05-17T21:18:18.512Z",
    "updated_at": "2020-05-17T21:18:18.512Z",
    "archived": false,
    "user_id": 23
  },
  {
    "id": 15,
    "address": "Carrera 76 #53 - 89",
    "description": "Lorem Ipsum is simply dummy text of the printing and typesetting industry.",
    "age": 40,
    "gender": "male",
    "status": "awaiting_result",
    "latitude": 6.261349,
    "longitude": -75.592187,
    "confirmed": false,
    "created_at": "2020-05-17T21:18:18.515Z",
    "updated_at": "2020-05-17T21:18:18.515Z",
    "archived": false,
    "user_id": 23
  },
  {
    "id": 16,
    "address": "Carrera 76 #53 - 89",
    "description": "Lorem Ipsum is simply dummy text of the printing and typesetting industry.",
    "age": 76,
    "gender": "unknown",
    "status": "suspicious",
    "latitude": 6.240317,
    "longitude": -75.584934,
    "confirmed": false,
    "created_at": "2020-05-17T21:18:18.517Z",
    "updated_at": "2020-05-17T21:18:18.517Z",
    "archived": false,
    "user_id": 23
  },
  {
    "id": 17,
    "address": "Carrera 76 #53 - 89",
    "description": "Lorem Ipsum is simply dummy text of the printing and typesetting industry.",
    "age": 76,
    "gender": "female",
    "status": "dead",
    "latitude": 6.204225,
    "longitude": -75.571587,
    "confirmed": true,
    "created_at": "2020-05-17T21:18:18.521Z",
    "updated_at": "2020-05-17T21:18:18.521Z",
    "archived": false,
    "user_id": 23
  },
  {
    "id": 18,
    "address": "Carrera 76 #53 - 89",
    "description": "Lorem Ipsum is simply dummy text of the printing and typesetting industry.",
    "age": 17,
    "gender": "female",
    "status": "positive",
    "latitude": 6.209088,
    "longitude": -75.571029,
    "confirmed": false,
    "created_at": "2020-05-17T21:18:18.524Z",
    "updated_at": "2020-05-17T21:18:18.524Z",
    "archived": false,
    "user_id": 23
  },
  {
    "id": 19,
    "address": "Carrera 76 #53 - 89",
    "description": "Lorem Ipsum is simply dummy text of the printing and typesetting industry.",
    "age": 84,
    "gender": "male",
    "status": "suspicious",
    "latitude": 6.215189,
    "longitude": -75.569914,
    "confirmed": true,
    "created_at": "2020-05-17T21:18:18.527Z",
    "updated_at": "2020-05-17T21:18:18.527Z",
    "archived": false,
    "user_id": 23
  },
  {
    "id": 20,
    "address": "Carrera 76 #53 - 89",
    "description": "Lorem Ipsum is simply dummy text of the printing and typesetting industry.",
    "age": 2,
    "gender": "male",
    "status": "suspicious",
    "latitude": 6.186434,
    "longitude": -75.582359,
    "confirmed": true,
    "created_at": "2020-05-17T21:18:18.529Z",
    "updated_at": "2020-05-17T21:18:18.529Z",
    "archived": false,
    "user_id": 23
  },
  {
    "id": 21,
    "address": "Carrera 76 #53 - 89",
    "description": "Lorem Ipsum is simply dummy text of the printing and typesetting industry.",
    "age": 53,
    "gender": "female",
    "status": "recovered",
    "latitude": 6.180503,
    "longitude": -75.587509,
    "confirmed": false,
    "created_at": "2020-05-17T21:18:18.532Z",
    "updated_at": "2020-05-17T21:18:18.532Z",
    "archived": false,
    "user_id": 23
  }
]