I want to create an api and an api
Reply content:
Create an api
It's easy to write a class or method that can be accessed through a browser and then output and return the corresponding data.JsonFormat
Api Authentication requires two considerations: client requests and requests from other services.
The easiest way to request a client is to control cross-origin access.Access-Control-Allow-Origin.
Currently, the mainstream idea of server verification is to generate a secret for the service that is allowed to access. the other party is required to generate a token according to certain rules. During access, a token is provided for local verification.
The specific token generation rules are designed according to the actual situation. Generally, they are various types of encryption and encoding.
Use token for verification. The procedure is as follows:
1. the client first uses the account and password to log on. a random string is generated after logon, written to the database, and returned to the client.
2. the client uses token to request protected resources
3. the server uses the token to search for the database. if the token is valid, the server continues the request. otherwise, 401 is returned.
The client and server respectively hold the same public key, the same algorithm, and calculate the sign signature. This signature is dynamically calculated and carried each time the API is called. before the server executes the interface, obtain the client parameters and use the public key to calculate the signature. you can compare the signature each time.