Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Strapi

Hierarchy

  • Strapi

Index

Constructors

constructor

  • new Strapi(baseURL: string, storeConfig?: StoreConfig, requestConfig?: AxiosRequestConfig): Strapi
  • Default constructor.

    Parameters

    • baseURL: string

      Your Strapi host.

    • Optional storeConfig: StoreConfig
    • Optional requestConfig: AxiosRequestConfig

    Returns Strapi

Properties

axios

axios: AxiosInstance

storeConfig

storeConfig: StoreConfig

Methods

authenticateProvider

clearToken

  • clearToken(): void
  • Remove token from Axios configuration

    Returns void

createEntry

  • createEntry(contentTypePluralized: string, data: any): Promise<any>
  • Create data

    Parameters

    • contentTypePluralized: string

      Type of entry pluralized

    • data: any

      New entry

    Returns Promise<any>

deleteEntry

  • deleteEntry(contentTypePluralized: string, id: string): Promise<any>
  • Delete an entry

    Parameters

    • contentTypePluralized: string

      Type of entry pluralized

    • id: string

      ID of entry

    Returns Promise<any>

forgotPassword

  • forgotPassword(email: string, url: string): Promise<void>
  • Sends an email to a user with the link of your reset password page. This link contains an URL param code which is required to reset user password. Received link url format https://my-domain.com/rest-password?code=privateCode.

    Parameters

    • email: string
    • url: string

      Link that user will receive.

    Returns Promise<void>

getEntries

  • getEntries(contentTypePluralized: string, params?: any): Promise<any[]>
  • List entries

    Parameters

    • contentTypePluralized: string
    • Optional params: any

      Filter and order queries.

    Returns Promise<any[]>

getEntry

  • getEntry(contentTypePluralized: string, id: string): Promise<any>
  • Get a specific entry

    Parameters

    • contentTypePluralized: string

      Type of entry pluralized

    • id: string

      ID of entry

    Returns Promise<any>

getEntryCount

  • getEntryCount(contentType: string, params?: any): Promise<any[]>
  • Get the total count of entries with the provided criteria

    Parameters

    • contentType: string
    • Optional params: any

      Filter and order queries.

    Returns Promise<any[]>

getFile

  • getFile(id: string): Promise<any>
  • Get file

    Parameters

    • id: string

      ID of entry

    Returns Promise<any>

getFiles

  • getFiles(params?: any): Promise<any[]>
  • Get files

    Parameters

    • Optional params: any

      Filter and order queries

    Returns Promise<any[]>

    Object[] Files data

getProviderAuthenticationUrl

  • getProviderAuthenticationUrl(provider: Provider): string

Private isBrowser

  • isBrowser(): boolean
  • Check if it runs on browser

    Returns boolean

login

  • login(identifier: string, password: string): Promise<Authentication>
  • Login by getting an authentication token.

    Parameters

    • identifier: string

      Can either be an email or a username.

    • password: string

    Returns Promise<Authentication>

    Authentication User token and profile

register

  • register(username: string, email: string, password: string): Promise<Authentication>
  • Register a new user.

    Parameters

    • username: string
    • email: string
    • password: string

    Returns Promise<Authentication>

    Authentication User token and profile

request

  • request(method: string, url: string, requestConfig?: AxiosRequestConfig): Promise<any>
  • Axios request

    Parameters

    • method: string

      Request method

    • url: string

      Server URL

    • Optional requestConfig: AxiosRequestConfig

      Custom Axios config

    Returns Promise<any>

resetPassword

  • resetPassword(code: string, password: string, passwordConfirmation: string): Promise<void>
  • Reset the user password.

    Parameters

    • code: string

      Is the url params received from the email link (see forgot password).

    • password: string
    • passwordConfirmation: string

    Returns Promise<void>

searchFiles

  • searchFiles(query: string): Promise<any[]>
  • Search for files

    Parameters

    • query: string

      Keywords

    Returns Promise<any[]>

setToken

  • setToken(token: string, comesFromStorage?: undefined | false | true): void
  • Set token on Axios configuration

    Parameters

    • token: string

      Retrieved by register or login

    • Optional comesFromStorage: undefined | false | true

    Returns void

updateEntry

  • updateEntry(contentTypePluralized: string, id: string, data: any): Promise<any>
  • Update data

    Parameters

    • contentTypePluralized: string

      Type of entry pluralized

    • id: string

      ID of entry

    • data: any

    Returns Promise<any>

upload

  • upload(data: FormData, requestConfig?: AxiosRequestConfig): Promise<any>
  • Upload files

    Browser example

    const form = new FormData();
    form.append('files', fileInputElement.files[0], 'file-name.ext');
    form.append('files', fileInputElement.files[1], 'file-2-name.ext');
    const files = await strapi.upload(form);

    Node.js example

    const FormData = require('form-data');
    const fs = require('fs');
    const form = new FormData();
    form.append('files', fs.createReadStream('./file-name.ext'), 'file-name.ext');
    const files = await strapi.upload(form, {
      headers: form.getHeaders()
    });

    Parameters

    • data: FormData

      FormData

    • Optional requestConfig: AxiosRequestConfig

    Returns Promise<any>

Generated using TypeDoc