A laravel-based APP interface [API] (2) Preface
According to the previous article, we have installed and debugged dingo/api, so the next step is to improve our API.
The first step must be to complete the registration function. now, let's name the first official API --
http://localhost/register
First, Analyze This API. This is an API registered by a user. a new user can register an account by accessing it before being authorized to perform other operations and enjoy other APP services. During access, we should enter the correct information. because the client is an APP, the fields to be entered should be the phone number and password.
After everything is ready, what callback should we get after the server completes the operation?
The next step is my understanding as a newbie. After successful registration, we should immediately return the token value for confirming user logon and store it as the APP's config variable until it is deleted or deleted after it exceeds the time limit.
After analysis, start to practice
Before we start, we need to install JWT (json web token) in the project. this is an API verification method. for details, see the document, its main function is to return a string of tokens after the client user sends a registration and login request, after successful logon, use the token value as the credential to verify whether you have the permission to obtain the resource.
For more information about how to install JWT, see JWT.
After JWT is installed, create a route first.
First open routes. php and modify the route
Route::post('/register', 'Auth\AuthenticateController@register');
Create a controller and run it in the laravel project.
php artisan make:controller Auth/AuthenticateController
Next, we use a pure html page as an APP to test the API and create a new test folder. The structure is as follows:
test/├── css/│ └── bootstrap.min.css├── js/│ ├── jquery.min.js│ └── bootstrap.min.js├── fonts/│ ├── glyphicons-halflings-regular.eot│ ├── glyphicons-halflings-regular.svg│ ├── glyphicons-halflings-regular.ttf│ ├── glyphicons-halflings-regular.woff│ └── glyphicons-halflings-regular.woff2└── register.html
Add content to the register.html file
Register
Switch Navigation
I ·APP
Register