justapi — /docs

Basic Usage

from justapi import JustAPIApp, JustAPITestClient

app = JustAPIApp()

@app.get("/hello")
def hello():
    return {"message": "Hello!"}

client = JustAPITestClient(app)

def test_hello():
    response = client.get("/hello")
    assert response["status"] == 200
    assert response["body"] == b'{"message":"Hello!"}'

Methods

Method Signature Description
get(path) GET path Send GET request
post(path, body) POST path with JSON body Send POST request
post_with(path, body, headers) POST path with headers POST with custom headers
put(path, body) PUT path with JSON body Send PUT request
patch(path, body) PATCH path with JSON body Send PATCH request
delete(path) DELETE path Send DELETE request

Response Format

All methods return a dict:

{
    "status": 200,        # HTTP status code
    "headers": {...},     # Response headers
    "body": b"..."        # Raw body bytes
}

POST with Headers

def test_with_auth():
    response = client.post_with(
        "/items",
        {"name": "Widget"},
        headers={"Authorization": "Bearer my-token"},
    )
    assert response["status"] == 201

With Database

client = JustAPITestClient(app, database="sqlite:///test.db")

See Also

JustAPI v2.0.9 — Open Source MIT License · Built with WebTUI · GitHub

NORMAL master justapi/docs
utf-8 Top 1:1