Showcase using Tile38 via pyle38 in a FastAPI application.
Report Bug
·
Request Feature
Showcase of using Tile38 with Pyle38 in a FastAPI application. Can be used as is, or be extended upon with other methods in the pyle38 repertoire of commands.
- Clone and install
git clone https://github.com/iwpnd/fastapi-tile38.git poetry install
- Setup environment
cp .env.dist .env
- Start your local stack
docker-compose up
- Test it!
pytest . -vv -s
Once the application is started you can checkout and interact with it via on localhost:8001/docs.
Or you can use it with http/curl:
echo '{ "data": { "type": "Feature", "geometry": {"type": "Point", "coordinates": [13.37, 52.25]}, "properties": {"id": "truck"}}}' \
| http post http://localhost:8001/vehicle x-api-key:test
> {
"elapsed": "37.5µs",
"ok": true
}
http get http://localhost:8001/search/within lat==52.25 lon==13.37 radius==1000 \
x-api-key:test
> {
"data": [
{
"id": "truck",
"object": {
"geometry": {
"coordinates": [
13.37,
52.25
],
"type": "Point"
},
"properties": {
"id": "truck"
},
"type": "Feature"
}
}
]
}
Or you use it with httpx/requests:
import httpx
vehicle = {
"type": "Feature",
"geometry": {"type": "Point", "coordinates": [13.37, 52.25]},
"properties": {"id": "truck"},
}
# store a vehicle
r = httpx.post(
url="http://localhost:8001/vehicle",
headers={"x-api-key":"test"},
json={"data": vehicle}
)
print(r.json())
> {
"elapsed": "70.8µs",
"ok": true
}
# get vehicle in a radius around a location
r = httpx.get(
url="http://localhost:8001/search/within",
headers={"x-api-key":"test"},
params={"lat":52.25,"lon":13.37,"radius":1000}
)
print(r.json())
> {
"data": [
{
"id": "truck",
"object": {
"geometry": {
"coordinates": [
13.37,
52.25
],
"type": "Point"
},
"properties": {
"id": "truck"
},
"type": "Feature"
}
}
]
}
You get the idea. And can use the rest.
Inputs are being validated at runtime with pydantic.
Distributed under the MIT License. See LICENSE
for more information.
Benjamin Ramser - @imwithpanda - [email protected]
Project Link: https://github.com/iwpnd/fastapi-tile38