1.0.12 • Published 1 year ago

strapi-common-type v1.0.12

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

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

1.0.12

1 year ago

1.0.11

1 year ago

1.0.10

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago