Options
Learn how to configure your Strapi SDK. ๐ฅ
url
- Type:
string
- Default:
process.env.STRAPI_URL || http://localhost:1337
The URL of the Strapi server. You can use the STRAPI_URL
environment variable to override the url
.
process.env.STRAPI_URL
is no longer used by default.prefix
- Type:
string
- Default:
/api
In Strapi v4, you have the capability to modify the API endpoint prefix
. The default prefix
is /api
, allowing you to access your API at http://localhost:1337/api
.
Check out the API configuration to learn how to change the default prefix.
store
- Type:
StoreConfig
key
- Type:
string
- Default:
strapi_jwt
- Type:
useLocalStorage
- Type:
boolean
- Default:
false
- Type:
cookieOptions
- Type:
object
- Default:
{ path: "/" }
- Type:
The store's configuration allows you to set the key
for the cookie name, as well as the localStorage key if you choose to use it thanks the useLocalStorage
boolean property. Additionally, you can provide cookieOptions
to be passed to the js-cookie package.
import Strapi from "strapi-sdk-js"
const strapi = new Strapi({
store: {
key: "strapi_jwt",
useLocalStorage: false,
cookieOptions: { path: "/" },
},
})
axiosOptions
- Type:
AxiosRequestConfig
- Default:
{}
Options to be passed to the Axios instance.
axiosCreate
- Type:
AxiosStatic['create']
- Default:
(config) => axios.create(config)
Axios instance creator where the axiosOptions
and merged internal defaults are passed as the first parameter. This is helpful if you want to customise the axios instance.
For example, lets say we want to implement request caching using the axios-cache-interceptor
package:
import axios from "axios";
import Strapi from "strapi-sdk-js"
import { setupCache } from "axios-cache-interceptor"
const strapi = new Strapi({
axiosCreate(config) {
const instance = axios.create(config)
return setupCache(instance)
}
})