A laravel-based APP interface [API] (2)

Source: Internet
Author: User
Tags what callback
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

  • Login

Register

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.