Returns the ID of the location saved.
Note
For now, just save one location for each request, please
-
URI
/api/v1/locations
-
Methods:
POST
-
Body
- Data params
- name: string
- latitude: float
- longitude: float
example:
- {"name":"", "latitude":5.6, "longitude":8.9}
- Data params
-
Success Response:
- Code: 201 CREATED
Content:{"location_id": "384a1f7a-466f-444d-b9f5-c372efd8c644"}
- Code: 201 CREATED
-
Error Response:
- Code: 404 NOT FOUND
Content:"response": "location not found"
- Code: 404 NOT FOUND
Return all existant locations in the database.
-
URL
/api/v1/locations
-
Methods:
GET
-
Success Response:
- Code: 200 OK
Content:{ "locations": [ { "id": "522bbd28-9118-4c8d-9fa1-effddbf5aacf", "latitude": 12.3467, "longitude": 9.12678, "name": "elm street" }, { "id": "5d39b607-8d83-4806-ad7f-0eaf55a5d3dd", "latitude": 12.3467, "longitude": 9.12678, "name": "st mary avenue" }] }
- Code: 200 OK
Returns a json with the requested location.
-
URI
/api/v1/locations/:location_id
-
Method:
GET
-
URL Params
Required:
id=[UUID]
-
Success Response:
- Code: 200 OK
Content:{ "location": { "id": "522bbd28-9118-4c8d-9fa1-effddbf5aacf", "latitude": 12.3467, "longitude": 9.12678, "name": "elm street" } }
- Code: 200 OK
-
Error Response:
- Code: 404 NOT FOUND
Content:{ "response": "location not found" }
- Code: 404 NOT FOUND
the locstorager service will be forwarded to the port 5600, this can be changed in the docker-compose file
We can use for this purpose clients like POSTMAN or INSOMNIA, for this case I'll use curl:
curl -i -H "Content-Type: application/json" -d '{"name":"location4", "longitude":11.4, "latitude":5.456}' http://localhost:5600/api/v1/locations
A success response will look like this:
HTTP/1.1 201 CREATED
Server: Werkzeug/2.3.6 Python/3.11.3
Date: Sun, 02 Jul 2023 19:11:56 GMT
Content-Type: application/json
Content-Length: 120
Connection: close
{
"location_id": "384a1f7a-466f-444d-b9f5-c372efd8c644"
}
Now for getting a single location we can send the following request:
curl -i -H "Content-Type: application/json" 'http://localhost:5600/api/v1/locations/5d39b607-8d83-4806-ad7f-0eaf55a5d3dd?='
A success response will look like this:
HTTP/1.1 200 OK
Server: Werkzeug/2.3.6 Python/3.11.3
Date: Sun, 02 Jul 2023 23:12:48 GMT
Content-Type: application/json
Content-Length: 154
Connection: close
{
"location": {
"id": "5d39b607-8d83-4806-ad7f-0eaf55a5d3dd",
"latitude": 12.3467,
"longitude": 9.12678,
"name": "st mary avenue"
}
}
For getting all the locations:
curl -i -H "Content-Type: application/json" http://localhost:5600/api/v1/locations
Returns the ID of the location saved.
-
URI
/api/v1/locations/ids
-
Methods:
POST
-
Body
- Data params
- ids: array[string]
example:
{"ids":["522bbd28-9118-4c8d-9fa1-effddbf5aacf", "896a3a26-61ea-4973-944f-31bf29cbf87a"]}
- Data params
-
Success Response:
- Code: 200
Content:{ "response": { "JOB ID": "cefb8958-f8e3-4558-a3ca-2fdf36ee684a", "message": "ids in the inbound queue"} }
- Code: 200
-
Error Response:
-
Code: 404 NOT FOUND
Content:{"response": "ids not found in database"}
Or
Code: 400 BAD REQUEST
Content:{"response": "some of the ids does not exists"}
-
the wrapper-piper service will be forwarded to the port 5700, this can be changed in the docker-compose file
This will deploy the service for saving locations, this service, a redis server, a postgres server and a worker for the process.
We can use for this purpose clients like POSTMAN or INSOMNIA, for this case I'll use curl:
curl -i -H "Content-Type: application/json" -d '{"ids":["896a3a26-61ea-4973-944f-31bf29cbf87a","d6de73e3-df1a-4ccf-bfa5-fff98fbf2e18"]}' http://localhost:5000/api/v1/locations/ids
Remember that you'll get those ids from the locstorager service
A success response will look like this:
HTTP/1.1 200 OK
Server: Werkzeug/2.3.6 Python/3.11.3
Date: Sun, 02 Jul 2023 19:11:56 GMT
Content-Type: application/json
Content-Length: 120
Connection: close
{
"response": {
"JOB ID": "d7451e7d-6d84-499e-a97b-b225f5bfcba1",
"message": "ids in the inbound queue"
}
}
In REDIS we'll see this as the last to elements for an inbound queue:
127.0.0.1:6379> LRANGE inbound -2 -1
1) "896a3a26-61ea-4973-944f-31bf29cbf87a"
2) "d6de73e3-df1a-4ccf-bfa5-fff98fbf2e18"
Now the result is in the outbound queue:
127.0.0.1:6379> LRANGE outbound -1 -1
1) "6.403878597381432"
We can get the result as a JSON response from api sending the job id
curl -i -H "Content-Type: application/json" -d '{"job_id":"d7451e7d-6d84-499e-a97b-b225f5bfcba1"}' http://localhost:5000/api/v1/locations/distance
A success response will look like this:
HTTP/1.1 200 OK
Server: Werkzeug/2.3.6 Python/3.11.3
Date: Sun, 02 Jul 2023 19:18:15 GMT
Content-Type: application/json
Content-Length: 103
Connection: close
{
"response": {
"distance": [
6.403878597381432
],
"message": "job finished"
}
}