MasoniteFramework / masonite4

Temporary Repository for a Masonite Rewrite for Masonite 4
14 stars 3 forks source link

Add API features - WIP #218

Open josephmancuso opened 2 years ago

josephmancuso commented 2 years ago

The first iteration of API improvements in M4 will be pretty small. Just the requirements.

So to build an API using these features is something like this:

Step 1

You can create a normal controller or create a resource controller:

python craft controller UserController -r

Step 2

Create your route, could be normal routes or you can use the new resource method which maps several routes to the matching controller method:

ROUTES = [
    Route.resource('users', 'UserController')
]

Step 3

Add the authentication controller:

python craft api:install

This will scaffold out the authentication controller so you can modify it

Step 4

Call /api/auth with your username and password and get back a token which is saved to the users table. You can use this token to make requests.

The JWTAuthenticationMiddleware will verify this token is passed and that it is valid