Skip to content
This repository has been archived by the owner on Jan 28, 2023. It is now read-only.

provide some common types and request functions support for strapi based frontend apps using typescript

Notifications You must be signed in to change notification settings

LittleBadBad/strapi-common-type

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

deprecated, rename module name to strapi-common-api

strapi-common-type

provide some common types and request functions support for strapi based frontend apps using typescript

data types was generated by types-4-strapi

see also strapi, typescript

install

npm install strapi-common-type -s

or

yarn add strapi-common-type

usage

at first, make sure you are developing using typescript, because this project only provide some typescript types and functions

types

err... there are too many types exported, here only introduce some key types

  • Query

query object followed by each strapi url, use qs library to stringify it, schema of query object follows the strapi api parameters

includes: locale, filters, publicationState, pagination, sort, fields, populate

import {Post} from "./Post";

export function getPosts(query?: Query<Post>): Promise<Return<Post[]>> {
    return strapiRequest.get(`/posts?${qs.stringify(query, {encodeValuesOnly: true})}`)
        .then(r => r.data)
}

// here your editor will give you some type hints
getPosts({filters: {title: {$contains: "test"}}})

functions

  • getMany

get many resources

Params:

type – strapi content-type name

query – strapi query object

  • getOne

get one resource

Params:

type – strapi content-type name

id – resources id

query – strapi query object

  • post

add one resource

Params:

type – strapi content-type name

data – post data

query – strapi query object

  • put

put one resource

Params:

type – strapi content-type name

id – resource id

data – post data

query – strapi query object

  • remove

remove one resource

Params:

type – strapi content-type name

id – resource id

query – strapi query object

objects

  • strapiRequest

based on axios module, you can customize your interceptors(such as add jwt token before request) or some other params

About

provide some common types and request functions support for strapi based frontend apps using typescript

Resources

Stars

Watchers

Forks

Packages

No packages published