Skip to content

0.6.0

Choose a tag to compare

@junah201 junah201 released this 08 Feb 07:00
· 18 commits to main since this release
e53217a

Highlight

Depends

Now, Nexify has a very powerful Dependency Injection system.

def common_parameters(
    q: Annotated[str | None, Query()] = None,
    skip: Annotated[int, Query()] = 0,
    limit: Annotated[int, Query()] = 100,
):
    return {"q": q, "skip": skip, "limit": limit}

@app.get("/items")
def read_items(
    common: Annotated[dict, Depends(common_parameters)],
):
    ...

Also, we supports dependencies that do some extra steps after finishing.
To do this, use yield instead of return, and write the extra steps (code) in the finally scope.

def get_db():
    db = Session()
    try:
        yield db
    finally:
        db.close()
        
@app.get("/user")
def read_user(db: Annotated[Session, Depends(get_db)]):

This is very similar to Depends in FastAPI.

Header and Cookie

In Nexify, you can extract values from request headers and cookies using Header and Cookie dependencies.

@app.get("/headers")
def read_headers(user_agent: Annotated[str, Header()], x_token: Annotated[str, Header()]) -> dict:
    return {"User-Agent": user_agent, "X-Token": x_token}

Similarly, you can extract cookies like this:

@app.get("/cookies")
def read_cookies(session_id: Annotated[str, Cookie()]) -> dict:
    return {"Session-ID": session_id}

Features

Tests

  • ✅ Update tests for middleware and path validation. Commit 564d6c3 by @junah201
  • ✅ Refactor tests to use fixtures for app initialization. Commit 7c3ca0a by @junah201
  • ✅ Refactor path tests to use parametrize. Commit cf3c536 by @junah201