From 28703a74c1e88b1b5fe881abeb071867b5ffa23a Mon Sep 17 00:00:00 2001 From: Tabot Kevin Date: Sun, 13 Oct 2024 01:33:21 +0100 Subject: [PATCH] quick start --- docs/index.rst | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/docs/index.rst b/docs/index.rst index f864460..4b00886 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -29,9 +29,26 @@ A light weight Python async framework with batteries included. api = dyne.API() - @api.route("/{greeting}") - async def greet_world(req, resp, *, greeting): - resp.text = f"{greeting}, world!" + @api.route("/create", methods=["POST"]) + @api.authenticate(basic_auth, role="user") + @api.input(BookCreateSchema, location="form") + @api.output(BookSchema) + @api.expect( + { + 401: "Invalid credentials", + } + ) + async def create(req, resp, *, data): + """Create book""" + + image = data.pop("image") + await image.save(image.filename) # File already validated for extension and size. + + book = Book(**data, cover=image.filename) + session.add(book) + session.commit() + + resp.obj = book if __name__ == "__main__": api.run()