strapi-client
An http client to easily access Strapi.io API.
Usage
Create an instance
const StrapiClient = const strapi = 'http://localhost:1337'
Login to the API
login(identifier, password)
const jwt user = await strapiconsoleconsole
If the login succeeds, the token will automatically be applied to the Authorization
header.
Get currently authenticated user
currentUser(token)
const user = await strapi
token
is optional. If a user has recently logged in, the token is automatically applied to the Authorization
header.
Persistence of the token
should be managed by the developer. To reauthenticate a user, just pass the token to the currentUser()
method.
const user = await strapi
Register an account
register(data)
let newUser = email: 'email@email.com' username: 'uname' password: 'pword' const jwt user = strapi consoleconsole
Count the entries of a content-type
count(contentType, query)
const numberOfUsers = await strapi
query
is optional. It accepts an object that is passed as HTTP params along with the GET
request. See Strapi's documentation about Parameters.
Create an entry
create(contentType, data)
const article = await strapi
Returns the created entry.
Get a list or a specific entry
get(contentType, id | query)
// Get a specific userconst user = await strapi // Get a list of usersconst users = await strapi
query
is optional. See the definition of this argument above. If a number
is passed instead of an object
, the method will return an object containing the entry of the given ID
. Otherwise, will return an array
of entries of the content-type.
Update an entry
update(contentType, id, updatedData)
const updatedArticle = await strapi
Returns the updated entry.
Delete an entry
delete(contentType, id)
const deletedArticle = await strapi
Returns the deleted entry.
Note:
- All method returns a
Promise.reject
if a server or connectivity issue occurs. - If the api fails to perform a request, it will return an object containing the error information.
TODO:
- Improve the documentation.
- Add other necessary methods.
- Find support and contributions. :P