Added litestar API endpoints#36
Conversation
|
|
||
|
|
||
| @get("/api/v1/users") | ||
| async def get_users( |
There was a problem hiding this comment.
get_user_stats
takes start end and hashtag as parameter , returns the user stats !
| from osmsg.api.app import app | ||
|
|
||
|
|
||
| def test_api_exposes_only_active_public_routes(): |
There was a problem hiding this comment.
assert test cases with actual api expected request and response !
| license-files = ["LICENSE"] | ||
| requires-python = ">=3.11" | ||
| dependencies = [ | ||
| "asyncpg>=0.30.0", |
There was a problem hiding this comment.
add api group and put those inside, uv is not needed in the deps !
There was a problem hiding this comment.
Thanks for the slim PR , beautiful work !
few points ;
add .env example !
add instructions to quickly test the api and the readme , to insert the data and get the api up , usually should be two commands ! expand test cases for real test assertion
|
Updated. I added:
|
|
The API is now hosted on Render and connected to a Neon Postgres database. Health endpoint: User stats endpoint: The database was populated using: |
| @@ -0,0 +1,71 @@ | |||
| from __future__ import annotations | |||
There was a problem hiding this comment.
not needed , this was only needed for the tools that supports <=3.11
| async def get_user_stats( | ||
| start: datetime, | ||
| end: datetime, | ||
| hashtag: str | None = None, |
There was a problem hiding this comment.
support list[str]
| @@ -0,0 +1,36 @@ | |||
| from __future__ import annotations | |||
There was a problem hiding this comment.
same here , remove
| limit: int = 100, | ||
| offset: int = 0, | ||
| ) -> list[dict[str, Any]]: | ||
| sql = """ |
There was a problem hiding this comment.
try to see if sql can be parametrized safely with the sql formatting !
| "litestar[standard]>=2.18.0", | ||
| ] | ||
| dev = [ | ||
| {include-group = "api"}, |
There was a problem hiding this comment.
dev doesn't need api ! api needs to be explicit
kshitijrajsharma
left a comment
There was a problem hiding this comment.
few minor changes !
Summary
Adds an initial Litestar API inside the
osmsg/apipackage.This includes two active endpoints for now:
GET /healthGET /api/v1/usersThe API uses
asyncpgto query PostgreSQL and reads the database connection from theDATABASE_URLenvironment variable.Changes
osmsg/api/package with Litestar app, DB pool setup, and users query./healthendpoint for API health checks./api/v1/usersendpoint to return ranked user statistics from the current osmsg PostgreSQL tables.Procfilefor deployment.litestar[standard],asyncpg, anduv.Notes
The API currently expects osmsg data to already be exported into PostgreSQL using the current osmsg schema:
userschangesetschangeset_statsstateExample local run: