[strapi series] how to debug the interface of public and authentication user Authorization in postman by strapi

1. Debugging of public users

For public users, if it is a get request, even if they are not in postman, it is easy to directly access the API in the browser and see the return interface.

First of all, if it is publica user, that is, if the request header is not included, Authorizationit is automatically publica user.

Then, if you are a user, every time you create a new article type, you need to check the corresponding permissionspublic in the corresponding publicpermissions .

As shown below:

image-20230723121412686

In this way, the interface can be debugged. If it is not checked, the debugging permission cannot be obtained .

image-20230723121621211

As shown in the figure below, after checking, you can directly debug the interface in the browser or postman, and the corresponding content will be returned. Otherwise it will show no permission.

image-20230723121656490

2. Debugging of authenticated users

Some content requires users to log in to access, and authentication is required in this case. That is, the token needs to be carried when requesting. Specific steps are as follows:

1. Create a new user to obtain token

image-20230723121942829

2. Call the interface for obtaining token to obtain token

Create a new request in postman, the request url is: 你的域名/api/auth/local , click send, and you can get the token. Message as follows:

image-20230723122203073

After getting the token, you can call any interface that requires authentication.

3. Bring the token to call the permission interface when requesting

For example, if you want to get a list of categories, go to the permissions and check it first , and the steps are the same public. Once you know it API地址, you can post it postman.

Then switch to Authorizationthe panel, select Bearer token, enter the token obtained in the previous request, and click 发送:

image-20230723122832415

If the information is filled in correctly tokenand has not expired, then the corresponding content will be obtained:

image-20230723123022757

3. Reference link

How to initiate an authentication request: https://docs.strapi.io/dev-docs/plugins/users-permissions#login

If you have difficulties in web front-end development, interviews, and front-end learning routes, you can add me V: imqdcnn. Answer questions for free, and technical experts who have been deep in the industry for many years will help you solve bugs.

I wish you can become an excellent WEB front-end development engineer!

Guess you like

Origin blog.csdn.net/imqdcn/article/details/131878347