2.3.3

Usage

Learn how to use this SDK. ๐Ÿ“š

New instance

Here is how you can instantiate the Strapi SDK.

Minimal
import Strapi from "strapi-sdk-js"

const strapi = new Strapi()
Custom
import Strapi from "strapi-sdk-js"

const strapi = new Strapi({
  url: "http://localhost:1337",
  prefix: "/api",
  store: {
    key: "strapi_jwt",
    useLocalStorage: false,
    cookieOptions: { path: "/" },
  },
  axiosOptions: {},
})

Check out the Options page for available options.

Content Types

All contentTypes methods are built based on the default Strapi CRUD operations.

await strapi.find("restaurants", { ...params })

Check out the CRUD Methods section for more information.

Authentication

The SDK comes with all the methods needed to handle authentication. You can find below the list of all the methods available:

Check out the Authentication Methods section for more information.

Advanced

Accessing user

Once you're logged in, you can access the user object which contains details about authenticated user through the strapi.user property.

Accessing axios

This SDK uses axios under the hood, you can directly access the axios instance through the strapi.axios property.

Custom request

If you've defined custom routes in your Strapi API that go beyond the REST scope, or if you want to extend the axios request configuration, you can do as below:

const response = await strapi.request("get", "/restaurants", {
  headers: {
    foo: "bar",
  },
})

See the axios config