07 - Uniformed Users
In this module, we will make a USER CREATE endpoint
Create User
Add the following code to user_view.py
Ok, we just added a lot so let's break it down
We created a blueprint object that defines what this collection of functions will be grouped under
when we use the decorator
@user_api.route()
, we are adding a route to theuser_api
blueprint. This is how we will define all of our routes.This way of adding routes makes it really easy to add routes to our app as all we need to do is add the blueprints
At the beginning of the create function, we load the data from the
request
argument (this is handled on Flask's side, it will be there when we run it) into theuser_schema
. This will automatically, map our attributes to the model and check for errors in the requestIf there are errors, we will send back a custom response using the
custom_response
function we created, to send back a 400 (bad request) to the clientIf the request body comes back clean from the schema and the email isn't used yet in our database, we are going to save the user and generate a token for the user
This token will be used to log in the user, we will implement this in the future
Then, the token will be sent back to client so they have access to it
We still don't have the authentication class yet. We will build this out in the next module
Last updated
Was this helpful?