"baseURL": "https://rain-forecast-risk-alert.herokuapp.com/"
- Cities
- Forecast risk
- Messages
- Users
- Protected requests
- Users
- Risk profile
- Patch user info
- Delete user
- Users
GET - /api/cities
Get all cities that our application currently cover.
Response:
HTTP/1.1: 200 - OK
[
{
"state": "Bahia",
"cities": [
"Rio de Contas"
]
},
{
"state": "Espírito Santo",
"cities": [
"Iconha",
"Vitória"
]
},
{
"state": "Minas Gerais",
"cities": [
"Coronel Fabriciano",
"Ipatinga"
]
},
{
"state": "Rio de Janeiro",
"cities": [
"Angra dos Reis",
"Magé",
"Nilópolis",
"Niterói",
"Nova Friburgo",
"Petrópolis",
"Rio de Janeiro"
]
},
{
"state": "Santa Catarina",
"cities": [
"Jaraguá do Sul"
]
},
{
"state": "São Paulo",
"cities": [
"Caraguatatuba",
"São José do Rio Pardo",
"São José dos Campos",
"São Paulo"
]
}
]
GET - /api/cities/from-state/<state_name>
GET - /api/cities/from-state/<state_uf>
Get all cities from an specific state.
The user can pass cities with any casing and with our withouth latin characters.
Example: sao paulo evaluates to São Paulo.
The requests below evaluate to the same response
GET EXAMPLE - /api/cities/from-state/São Paulo
GET EXAMPLE - /api/cities/from-state/sãO pAulO
GET EXAMPLE - /api/cities/from-state/SaO pAulO
GET EXAMPLE - /api/cities/from-state/sp
GET EXAMPLE - /api/cities/from-state/sP
Response:
HTTP/1.1: 200 - OK
[
{
"state": "São Paulo",
"cities": [
"Caraguatatuba",
"São José do Rio Pardo",
"São José dos Campos",
"São Paulo"
]
}
]
POST - /api/forecast-risk
Send a list of cities, states and precipitation and returns a list of endangered cities along with a quantity of users in the cities. The precipitation values and which values correspond to a danger were defined in the code.
A list of these parameters:
Field | Type | Description |
---|---|---|
city | string | A city name |
state | string | The city state |
precipitation | integer or float | A precipitation integer value in mm |
Body:
[
{
"city": "Petrópolis",
"state": "Rio de Janeiro",
"precipitation": 80
},
{
"city": "São Paulo",
"state": "São Paulo",
"precipitation": 30
}
]
Response:
HTTP/1.1: 200 - OK
{
"endangered_cities": [
{
"city": "Petrópolis",
"state": "Rio de Janeiro",
"users_warned": 2
}
]
}
Forecast risk request with missing keys
Body:
[
{
"state": "Rio de Janeiro",
"precipitation": 80
},
{
"city": "São Paulo",
"state": "São Paulo"
}
]
Response:
HTTP/1.1: 400 - BAD REQUEST
{
"error": "missing keys",
"expected_keys": ["city", "state", "precipitation"],
"missing_keys": [
{
"request": {
"state": "Rio de Janeiro",
"precipitation": 80
},
"missing_keys": ["city"]
},
{
"request": {
"city": "São Paulo",
"state": "São Paulo"
},
"missing_keys": ["precipitation"]
}
]
}
Forecast risk request with invalid keys
Body:
[
{
"city": "Petrópolis",
"state": "Rio de Janeiro",
"precipitation": 80,
"flood_risk": "high"
},
{
"city": "São Paulo",
"state": "São Paulo",
"precipitation": 30
}
]
Response:
HTTP/1.1: 400 - BAD REQUEST
{
"error": "invalid keys",
"expected_keys": ["city", "state", "precipitation"],
"invalid_keys": [
{
"request": {
"city": "Petrópolis",
"state": "Rio de Janeiro",
"precipitation": 80,
"flood_risk": "high"
},
"invalid_keys": ["flood_risk"]
}
]
}
Forecast risk request with invalid value types
Body:
[
{
"city": "Petrópolis",
"state": "Rio de Janeiro",
"precipitation": "high"
},
{
"city": "São Paulo",
"state": 23,
"precipitation": { "mm": 80 }
}
]
Response:
HTTP/1.1: 400 - BAD REQUEST
{
"error": "invalid type",
"expected_type": {
"city": "str",
"state": "str",
"precipitation": "int or float"
},
"received_type": [
{
"request": {
"city": "Petrópolis",
"state": "Rio de Janeiro",
"precipitation": "high"
},
"invalid_types": {
"precipitation": "str"
}
},
{
"request": {
"city": "São Paulo",
"state": 23,
"precipitation": {
"mm": 80
}
},
"invalid_types": {
"state": "int",
"precipitation": "dict"
}
}
]
}
Forecast risk request with invalid request type
Body:
{
"city": "Petrópolis",
"state": "Rio de Janeiro",
"precipitation": 80
}
Response:
HTTP/1.1: 400 - BAD REQUEST
{
"error": "invalid type",
"expected_type": "type",
"received_type": "dict"
}
GET - /api/messages
Get a message log for all the messages our application has sended.
Success-Response:
HTTP/1.1: 200 OK
[
{
"id": 1,
"date": "Thu, 05 May 2022 18:11:52 GMT"
},
{
"id": 2,
"date": "Thu, 05 May 2022 18:11:52 GMT"
},
{
"id": 3,
"date": "Fri, 06 May 2022 11:54:38 GMT"
}
]
POST /api/users/signup
Register a new user.
Field | Type | Description |
---|---|---|
name | string | User name |
string | User email | |
phone | string | User phone number |
cep | string | User location cep number |
password | string | User password |
Body:
{
"name": "JOhN DOE",
"email": "[email protected]",
"phone": "(47) 9999-9999",
"cep": "03478-070",
"password": "1234"
}
Response:
HTTP/1.1: 201 - CREATED
{
"name": "John Doe",
"email": "[email protected]",
"phone": "(47) 9999-9999",
"address": "03478-070",
"city": "São Paulo",
"state": "São Paulo"
}
Signup with duplicated email
Body:
{
"name": "JOhN Doe Jr",
"email": "[email protected]",
"phone": "(47) 88888-8888",
"cep": "03478-070",
"password": "1234"
}
Response:
HTTP/1.1: 409 - CONFLICT
{
"error": "unique email error"
}
Signup with duplicated phone
Body:
{
"name": "JOhN DOE jr",
"email": "[email protected]",
"phone": "(47) 9999-9999",
"cep": "03478-070",
"password": "1234"
}
Response:
HTTP/1.1: 409 - CONFLICT
{
"error": "unique phone error"
}
Signup with missing keys
Body:
{
"name": "JOhN DOE",
"email": "[email protected]",
"phone": "(47) 9999-9999"
}
Response:
HTTP/1.1: 400 - BAD REQUEST
{
"error": "missing keys",
"expected_keys": [
"name",
"phone",
"email",
"password",
"cep"
],
"missing_keys": [
"password",
"cep"
]
}
Signup with invalid keys
Body:
{
"name": "JOhN DOE",
"email": "[email protected]",
"phone": "(47) 9999-9999",
"cep": "03478-070",
"password": "1234",
"status": "fine"
}
Response:
HTTP/1.1: 400 - BAD REQUEST
{
"error": "invalid keys",
"expected_keys": [
"name",
"phone",
"email",
"password",
"cep"
],
"invalid_keys": [
"status"
]
}
Signup with invalid value types
Body:
{
"name": ["JOhN", "DOE"],
"email": {"name":"johndoe", "domain": "mail.com"},
"phone": 0099999999,
"cep": 63478.070,
"password": "1234"
}
Response:
HTTP/1.1: 400 - BAD REQUEST
{
"error": "invalid type",
"expected_type": {
"name": "str",
"phone": "str",
"email": "str",
"password": "str",
"cep": "str"
},
"received_type": {
"name": "list",
"email": "dict",
"phone": "int",
"cep": "float"
}
}
Signup with invalid email format
Body:
{
"name": "JOhN DOE",
"email": "johndoemailcom",
"phone": "(00) 99999-9999",
"cep": "03478-070",
"password": "1234"
}
Response:
HTTP/1.1: 400 - BAD REQUEST
{
"error": "invalid email format",
"expected_format": "[email protected]",
"received_format": "johndoemailcom"
}
Signup with invalid phone format
Body:
{
"name": "JOhN DOE",
"email": "[email protected]",
"phone": "00999999999",
"cep": "00000-000",
"password": "1234"
}
Response:
HTTP/1.1: 400 - BAD REQUEST
{
"error": "invalid phone format",
"expected_format": "(xx) xxxxx-xxxx",
"received_format": "00999999999"
}
Signup with invalid zip code format
Body:
{
"name": "JOhN DOE",
"email": "[email protected]",
"phone": "(00) 99999-9999",
"cep": "00000-000",
"password": "1234"
}
Response:
HTTP/1.1: 400 - BAD REQUEST
{
"error": "zip code not found"
}
Signup with city out of coverage
Body:
{
"name": "JOhN DOE",
"email": "[email protected]",
"phone": "(00) 99999-9999",
"cep": "06803-440",
"password": "1234"
}
Response:
HTTP/1.1: 400 - BAD REQUEST
{
"error": "city out of coverage",
"received_city": "Embu das Artes",
"cities_coverage": [
{
"city": "Rio de Janeiro",
"uf": "RJ"
},
{
"city": "São Paulo",
"uf": "SP"
},
{
"city": "Petrópolis",
"uf": "RJ"
},
{
"city": "Rio de Contas",
"uf": "BA"
},
{
"city": "Nova Friburgo",
"uf": "RJ"
},
{
"city": "Iconha",
"uf": "ES"
},
{
"city": "Caraguatatuba",
"uf": "SP"
},
{
"city": "Angra dos Reis",
"uf": "RJ"
},
{
"city": "Coronel Fabriciano",
"uf": "MG"
},
{
"city": "Niterói",
"uf": "RJ"
},
{
"city": "Nilópolis",
"uf": "RJ"
},
{
"city": "Magé",
"uf": "RJ"
},
{
"city": "Jaraguá do Sul",
"uf": "SC"
},
{
"city": "Ipatinga",
"uf": "MG"
},
{
"city": "Vitória",
"uf": "ES"
},
{
"city": "São José do Rio Pardo",
"uf": "SP"
},
{
"city": "São José dos Campos",
"uf": "SP"
}
]
}
POST /api/users/signin
Signin a user.
Field | Type | Description |
---|---|---|
name | string | User name |
password | string | User password |
Body:
{
"email": "[email protected]",
"password": "1234"
}
Response:
HTTP/1.1: 200 - OK
{
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJmcmVzaCI6ZmFsc2UsImlhdCI6MTY1MTg1MTM1MywianRpIjoiNjZlOTc3NmMtOWIxNC00ODM2LWFhNzYtNWI1NTg4NTIyY2Q3IiwidHlwZSI6ImFjY2VzcyIsInN1YiI6ODQ2LCJuYmYiOjE2NTE4NTEzNTMsImV4cCI6MTY1MTg1MjI1M30.0krUZf6hNRx8xsMz_S9330uRms0AYlPJQWv-k6l7XB4"
}
Signin with invalid credentials
Body:
{
"email": "[email protected]",
"password": "12345"
}
Response:
HTTP/1.1: 404 - NOT FOUND
{
"message": "Unauthorized"
}
Signin with missing keys
Body:
{
"email": "[email protected]"
}
Response:
HTTP/1.1: 400 - BAD REQUEST
{
"error": "missing keys",
"expected_keys": [
"email",
"password"
],
"missing_keys": [
"password"
]
}
Signin with invalid keys
Body:
{
"username": "johndoe",
"email": "[email protected]",
"password": "1234"
}
Response:
HTTP/1.1: 400 - BAD REQUEST
{
"error": "invalid keys",
"expected_keys": [
"email",
"password"
],
"invalid_keys": [
"username"
]
}
Signin with invalid value types
Body:
{
"email": {"name":"johndoe", "domain" : "mail.com"},
"password": 12345
}
Response:
HTTP/1.1: 400 - BAD REQUEST
{
"error": "invalid type",
"expected_type": {
"email": "str",
"password": "str"
},
"received_type": {
"email": "dict",
"password": "int"
}
}
The following requests needs a bearer token at the authorization header.
headers: {
"Authorization": "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJmcmVzaCI6ZmFsc2UsImlhdCI6MTY1MDgyNzQ4MywianRpIjoiYzE1Y2M4MjktYmU2Ni00Y2MxLTgzYmEtZDVmY2ZmZjc4YmY5IiwidHlwZSI6ImFjY2VzcyIsInN1YiI6IjVjMDRlYTI2LTNjMmEtNDUxMS05OGNkLTMyODRiNjRmZjcwMCIsIm5iZiI6MTY1MDgyNzQ4MywiZXhwIjoxNjUwODI4MzgzfQ.AJ9cO8nxDuCO4ws61zCs7ng32lJo2fZCoJXeml6VNcE"
}
POST /api/user/risk-profile
Add a risk profile to a user
Field | Type | Description |
---|---|---|
live_nearby_river | bool | A boolean to check if the user lives nearby a river |
live_nearby_mountain | bool | A boolean to check if the user lives nearby a mountain |
Body:
{
"live_nearby_river": true,
"live_nearby_mountain": false
}
Response:
HTTP/1.1: 201 - CREATED
{
"name": "John Doe",
"phone": "(47) 9999-9999",
"email": "[email protected]",
"risks": [
{
"title": "FLOOD",
"text": "FORTES CHUVAS: RISCO DE ALAGAMENTO, reúna pertences importantes (documentos e dinheiro) e dirija-se p/ o ponto de apoio da Defesa Civil mais próximo."
}
]
}
Risk profile without token
Body:
{
"live_nearby_river": true,
"live_nearby_mountain": false
}
Response:
HTTP/1.1: 401 - UNAUTHORIZED
{
"msg": "Missing Authorization Header"
}
Risk profile with invalid token
Body:
{
"live_nearby_river": true,
"live_nearby_mountain": false
}
Response:
HTTP/1.1: 422 - UNPROCESSABLE ENTITY
{
"msg": "Signature verification failed"
}
Risk profile with user not found
Body:
{
"live_nearby_river": true,
"live_nearby_mountain": false
}
Response:
HTTP/1.1: 404 - NOT FOUND
{
"error": "user not found"
}
Risk profile with missing keys
Body:
{
"live_nearby_mountain": true
}
Response:
HTTP/1.1: 400 - BAD REQUEST
{
"error": "missing keys",
"expected_keys": [
"live_nearby_river",
"live_nearby_mountain"
],
"missing_keys": [
"live_nearby_river"
]
}
Risk profile with invalid keys
Body:
{
"live_nearby_river": true,
"live_nearby_mountain": true,
"live_nearby_volcano": true
}
Response:
HTTP/1.1: 400 - BAD REQUEST
{
"error": "invalid keys",
"expected_keys": [
"live_nearby_river",
"live_nearby_mountain"
],
"invalid_keys": [
"live_nearby_volcano"
]
}
Risk profile with invalid value types
Body:
{
"live_nearby_river": 0,
"live_nearby_mountain": "yes"
}
Response:
HTTP/1.1: 400 - BAD REQUEST
{
"error": "invalid type",
"expected_type": {
"live_nearby_river": "bool",
"live_nearby_mountain": "bool"
},
"received_type": {
"live_nearby_river": "int",
"live_nearby_mountain": "str"
}
}
PATCH /api/user
Patch the user info
Field | Type | Description |
---|---|---|
name | string | User name |
string | User email | |
phone | string | User phone number |
cep | string | User location cep number |
Body:
{
"name": "John doe Jr"
}
Response:
HTTP/1.1: 204 - NO CONTENT
Patch user without token
Body:
{
"name": "Little johnny"
}
Response:
HTTP/1.1: 401 - UNAUTHORIZED
{
"msg": "Missing Authorization Header"
}
Patch user with invalid token
Body:
{
"name": "Little johnny"
}
Response:
HTTP/1.1: 422 - UNPROCESSABLE ENTITY
{
"msg": "Missing Authorization Header"
}
Patch a not found user
Body:
{
"name": "Little johnny"
}
Response:
HTTP/1.1: 404 - NOT FOUND
{
"error": "user not found"
}
Patch user with invalid keys
Body:
{
"mother_name": "Olivia"
}
Response:
HTTP/1.1: 400 - BAD REQUEST
{
"error": "invalid keys",
"expected_keys": [
"name",
"phone",
"email",
"password",
"cep"
],
"invalid_keys": [
"mother_name"
]
}
Patch user with invalid value types
Body:
{
"name": true,
"email": {"name":"john", "domain":"mail.com"},
"phone": [55, "99999", 55.55],
"cep": 99999.999
}
Response:
HTTP/1.1: 400 - BAD REQUEST
{
"error": "invalid type",
"expected_type": {
"name": "str",
"phone": "str",
"email": "str",
"password": "str",
"cep": "str"
},
"received_type": {
"name": "bool",
"email": "dict",
"phone": "list",
"cep": "float"
}
}
Patch user with duplicated email
Body:
{
"name": "[email protected]"
}
Response:
HTTP/1.1: 409 - CONFLICT
{
"error": "unique email error"
}
Body:
{
"phone": "(88) 88888-8888"
}
Response:
HTTP/1.1: 409 - CONFLICT
{
"error": "unique phone error"
}
Body:
{
"cep": "00000-000"
}
Response:
HTTP/1.1: 404 - NOT FOUND
{
"error": "zip code not found"
}
Body:
{
"cep": "06803-440"
}
Response:
HTTP/1.1: 400 - BAD REQUEST
{
"error": "city out of coverage",
"received_city": "Embu das Artes",
"cities_coverage": [
{
"city": "Rio de Janeiro",
"uf": "RJ"
},
{
"city": "São Paulo",
"uf": "SP"
},
{
"city": "Petrópolis",
"uf": "RJ"
},
{
"city": "Rio de Contas",
"uf": "BA"
},
{
"city": "Nova Friburgo",
"uf": "RJ"
},
{
"city": "Iconha",
"uf": "ES"
},
{
"city": "Caraguatatuba",
"uf": "SP"
},
{
"city": "Angra dos Reis",
"uf": "RJ"
},
{
"city": "Coronel Fabriciano",
"uf": "MG"
},
{
"city": "Niterói",
"uf": "RJ"
},
{
"city": "Nilópolis",
"uf": "RJ"
},
{
"city": "Magé",
"uf": "RJ"
},
{
"city": "Jaraguá do Sul",
"uf": "SC"
},
{
"city": "Ipatinga",
"uf": "MG"
},
{
"city": "Vitória",
"uf": "ES"
},
{
"city": "São José do Rio Pardo",
"uf": "SP"
},
{
"city": "São José dos Campos",
"uf": "SP"
}
]
}
PATCH /api/user
To update the user password is required to pass an old_password key.
NOTE: You can also pass any of the following parameters.
Field | Type | Description |
---|---|---|
name | string | User name |
string | User email | |
phone | string | User phone number |
cep | string | User location cep number |
password | string | User password |
old_password | string | User old password to confirm new password |
Body:
{
"name": "Mary B",
"password": "4321",
"old_password": "1234"
}
Response:
HTTP/1.1: 204 - NO CONTENT
Patch user password without old password key
Body:
{
"name": "Mary B",
"password": "4321"
}
Response:
HTTP/1.1: 401 - UNAUTHORIZED
{
"error": "missing old password value",
"message": "to update the password, an old_password key is required"
}
Patch user password without password key and with old password key
Body:
{
"name": "Mary B",
"old_password": "4321"
}
Response:
HTTP/1.1: 401 - UNAUTHORIZED
{
"error": "invalid keys",
"expected_keys": [
"name",
"phone",
"email",
"password",
"cep"
],
"invalid_keys": [
"old_password"
]
}
DELETE /api/user
Delete an user
Response:
HTTP/1.1: 204 - NO CONTENT
Delete user without token
Response:
HTTP/1.1: 401 - UNAUTHORIZED
{
"msg": "Missing Authorization Header"
}