Python - api.get()
Register an API route and set a specific HTTP GET handler on that route.
from nitric.resources import apifrom nitric.application import NitricpublicApi = api("public")@publicApi.get("/customer/:customerId")async def customer_get(ctx):id = ctx.req.params.customerIdctx.res.body = f"Getting {id}"Nitric.run()
Parameters
- Name
- match
- Type
- string
- Description
- The path matcher to use for the route. Matchers accept path parameters in the form of a colon prefixed string. The string provided will be used as that path parameter's name when calling middleware and handlers. See Examples 
 
- Name
- options
- Type
- MethodOptions
- Description
- Options to configure the route such as security options. 
 
Examples
Register a handler for GET requests
from nitric.resources import apifrom nitric.application import NitricpublicApi = api("public")@publicApi.get("/customer/:customerId")async def hello_world(ctx):id = ctx.req.params.customerIdctx.res.body = f"Getting {id}"Nitric.run()
Last updated on Oct 11, 2024