nustack
ReferenceFabrics

nu.http

HTTP fabric: declarative service endpoints over httpx, sync and async. Verb refs declare endpoints on a nu.Service; calling them yields an interaction that runs against the ctx-bound HttpFabric client, returns parsed JSON, and raises on non-2xx.

Fabric

from nu.http import HttpFabric

NameSortSignatureEffectMeaning
HttpFabricclassHttpFabric(*, base_url="", headers=None, timeout=30.0)read/writeholds a sync httpx.Client and async httpx.AsyncClient; opens on setup/asetup

Refs

from nu.http import GETRef, POSTRef, PUTRef, PATCHRef, DELETERef

One MethodRef subclass per HTTP verb. Use .method(path, **defaults) on a nu.Service class body to declare an endpoint; calling the resolved attribute with kwargs constructs the matching interaction.

NameSortSignatureEffectMeaning
GETRefclassGETRef.method(path, **defaults)puredeclare a GET endpoint at path; call yields HttpGet
POSTRefclassPOSTRef.method(path, **defaults)puredeclare a POST endpoint at path; call yields HttpPost
PUTRefclassPUTRef.method(path, **defaults)puredeclare a PUT endpoint at path; call yields HttpPut
PATCHRefclassPATCHRef.method(path, **defaults)puredeclare a PATCH endpoint at path; call yields HttpPatch
DELETERefclassDELETERef.method(path, **defaults)puredeclare a DELETE endpoint at path; call yields HttpDelete

Interactions

from nu.http import HttpGet, HttpPost, HttpPut, HttpPatch, HttpDelete

The five interactions produced when a verb ref is called with kwargs. HttpGet is a ScalarQuery (safe read). The other four are ScalarActions and declare a mutation on their target service. All yield the parsed JSON body and raise on non-2xx.

NameSortSignatureEffectMeaning
HttpGetScalarQueryHttpGet(ref, kwargs)actionGET request; yields parsed JSON
HttpPostScalarActionHttpPost(ref, kwargs)actionPOST request; yields parsed JSON response
HttpPutScalarActionHttpPut(ref, kwargs)actionPUT request; yields parsed JSON response
HttpPatchScalarActionHttpPatch(ref, kwargs)actionPATCH request; yields parsed JSON response
HttpDeleteScalarActionHttpDelete(ref, kwargs)actionDELETE request; yields parsed JSON (empty on 204)

Presets

from nu.http import bind

NameSortSignatureEffectMeaning
bindfunctionbind(service_cls, *, base_url="", headers=None, timeout=30.0)pureProvide an HttpFabric tagged by the service class

On this page