Open josephmancuso opened 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:
You can create a normal controller or create a resource controller:
python craft controller UserController -r
Create your route, could be normal routes or you can use the new resource method which maps several routes to the matching controller method:
resource
ROUTES = [ Route.resource('users', 'UserController') ]
Add the authentication controller:
python craft api:install
This will scaffold out the authentication controller so you can modify it
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.
/api/auth
The JWTAuthenticationMiddleware will verify this token is passed and that it is valid
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:
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:Step 3
Add the authentication controller:
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