strapi 其他操作相关帖子参考 相关
api注册
http://localhost:1337/api/auth/local/register
代码演示
var myHeaders = new Headers(); myHeaders.append("Content-Type", "application/json");
var raw = JSON.stringify({ "username": "test_2", "email": "22@qq.com", "password": "123456" });
var requestOptions = { method: 'POST', headers: myHeaders, body: raw, redirect: 'follow' };
fetch("http://localhost:1337/api/auth/local/register", requestOptions) .then(response => response.text()) .then(result => console.log(result)) .catch(error => console.log('error', error));
|
api 获取token
http://localhost:1337/api/auth/local
代码演示
var myHeaders = new Headers(); myHeaders.append("Content-Type", "application/json");
var raw = JSON.stringify({ "identifier": "691105882@qq.com", "password": "123456" });
var requestOptions = { method: 'POST', headers: myHeaders, body: raw, redirect: 'follow' };
fetch("http://localhost:1337/api/auth/local", requestOptions) .then(response => response.text()) .then(result => console.log(result)) .catch(error => console.log('error', error));
|
api 获取用户信息
http://localhost:1337/api/users/me?populate=*
var myHeaders = new Headers(); myHeaders.append("Authorization", "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MywiaWF0IjoxNzMwNzc4Njk3LCJleHAiOjE3MzMzNzA2OTd9.hE9jMVjrcgih3nKua0NTuYPu1fHJZHCSacXQ9zwBNV4");
var requestOptions = { method: 'GET', headers: myHeaders, redirect: 'follow' };
fetch("http://localhost:1337/api/users/me?populate=*", requestOptions) .then(response => response.text()) .then(result => console.log(result)) .catch(error => console.log('error', error));
|
更新user用户信息
http://localhost:1337/api/users/3
3是对应的user_id,默认只有超管才有权限请在设置开启更新权限。
开启后更新对应用户信息在header头传入对应的token
var myHeaders = new Headers(); myHeaders.append("Authorization", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MywiaWF0IjoxNzMwNzk2MzQ3LCJleHAiOjE3MzMzODgzNDd9.RnLrfZj6OQmFj4eehUwydhafdQtW5oSEqK1eEMiDh1M"); myHeaders.append("Content-Type", "application/json");
var raw = JSON.stringify({ "shops": 1 });
var requestOptions = { method: 'PUT', headers: myHeaders, body: raw, redirect: 'follow' };
fetch("http://localhost:1337/api/users/3", requestOptions) .then(response => response.text()) .then(result => console.log(result)) .catch(error => console.log('error', error));
|
如上操作是更新对应用户对应的商品。
快捷指令创建相关操作
npx strapi generate