Gits Strapi

This package is used to make it easier when you want to integrate with the strapi

Gits Strapi

# Prerequisites

This library uses the gits_http package

# Yout must know

Requests return a response as an object which usually includes the following keys:

  • data: the response data itself, which could be:

    • a single entry, as an object with the following keys:
      • id (number)
      • attributes (object)
      • meta (object)
    • a list of entries, as an array of objects
    • a custom response
  • meta (object): information about pagination, publication state, available locales, etc.

  • error (object, optional): information about any error thrown by the request

# Usage

First of all, initialize the gits_strapi in this way

 final GitsStrapi strapi = GitsStrapi(
      timeout: 30000,
      showLog: true,
      gitsInspector: GitsInspector(),

after that we can use some main functions like

Auth Login

Used for standard strapi login needs, if there is a need beyond that then use another function

AuthResponse loginResponse = await strapi.login(
        endpoint: Uri.parse(""),
        body: {"identifier": "identifier", "password": "password"});

Auth Register

Used for standard strapi register needs, if there is a need beyond that then use another function

AuthResponse registerResponse = await strapi.register(
        endpoint: Uri.parse(""),
        body: {
          "username": "username",
          "email": "email",
          "password": "password"

Get Single Response

Used to retrieve data for a single object, if you need to retrieve a lot of data use Get Collection Response

 Uri endpointProductOne =
      const StrapiRequest(
        populate: ["images"],

    SingleResponse<DataResponse<ProductResponse>> singleResponse =
        await strapi.getSingle(endpoint: endpointProductOne).then((value) {
      var attr = ProductResponse.fromMap(;
      var data = DataResponse(id:, attributes: attr);
      return SingleResponse(data: data, meta: value.meta, error: value.error);

Get Collection Response

Used to retrieve data based on a list of objects, if necessary retrieve single object data Get Single Response

 Uri endpointProducts = Uri.parse("")
            const StrapiRequest(page: 1, pageSize: 3, sort: ['id:desc']));

    CollectionResponse<DataResponse<ProductResponse>> collectionResponse =
        await strapi.getCollection(endpoint: endpointProducts).then((value) {
      var data = <DataResponse<ProductResponse>>[]; {
            attributes: ProductResponse.fromMap(item.attributes),
      return CollectionResponse(
          data: data, meta: value.meta, error: value.error);

(Get) Select

Used for GET method requirements

Response select = await Uri.parse("endpoint"));

(POST) Create

Used for POST method requirements

var insertBody = {
      "data": {
        "name": "name",
        "description": "description",
        "price": 10000,
        "stock": 5,
    Response insert = await strapi.create(
        endpoint: Uri.parse(""),
        headers: {
              'Bearer eyJhxdcfOgJwUwI1NiIsInR5cCI6IkpXVCJ9.eyJaZcIvMiwfaWF0IjoxNjYxMjM2OTgwLCJleHAiOjE2NjM4Mjg5ODB9.Cb-wP8EUPUcwp76VD_IWqsw5nvi9xv0QqH0Ng4EB1UI'
        body: insertBody);

(PUT) Update

Used for PUT method requirements

var updateBody = {
      "data": {
        "name": "name",
        "description": "description",
        "price": 50000,
        "stock": 3,
    Response updateResponse = await strapi.update(
        id: "1",
        endpoint: Uri.parse(""),
        headers: {
              'Bearer eyJhbGciOiJIazIwdivsPnRKDCI6IkpXVCJ9.eyJpZCI6MiwiaWF0IjoxNjYxMjM2OTUCLVJleHAiOjE2NjM4Mjg5ODB9.Cb-wP8EUPUcwp76VD_IWqsw5nvi9xv0QqH0Ng4EB1UI'
        body: updateBody)


Used for DELETE method requirement

 Response deleteResponse = await strapi.delete(headers: {
          'Bearer eyJhbGciOiJIUzI1NiIsInCX5FCI6IkpXVCJ9.eyJpZCI6MiwiaWF0IjoxNjYxMjM2OTgwLCJleHA_1OjE2NjM4Mjg5ODB9.Cb-wP8EUPUcwp76VD_IWWsC5GFvi9xv0QqH0Ng4EB1UI'
    }, endpoint: Uri.parse(""), id: "9");

# Helper

Strapi Request

we have provided some required parameter requests such as:

  • populate `List
  • fields `List
  • sort `List
  • withCount `bool`
  • pageSize `pageSize`
  • page `page`

for an example like this

      fields: ['id','name'],
      populate: ['images','transactions'],
      sort: ['id:desc'],
      page: 1,
      pageSize: 10,
      withCount: true,

Entity Mapper

As for the need to convert Response to Entity which has been provided for some Base Response below:

  • SingleResponse
  • CollectionResponse
  • DataResponse
  • MetaResponse
  • PaginationResponse
  • ErrorResponse
  • AuthResponse
  • UserResponse
  • ThumbnailResponse
  • FormatsResponse
  • ImageResponse

how to use it like this for responses which have generic class

var collectionEntity = collectionResponse.toEntity(
      (data) => data
          .map((item) => (item as DataResponse)
              .toEntity((attr) => (attr as ProductResponse).toEntity()))

if it doesn't have a generic class


Additional information

For additional information we have several main response bases that will be used frequently

  • SingleResponse : to handle response {"data (single object)","meta","error"}
  • CollectionResponse : to handle response {"data (is an array object)","meta","error"}
  • DataResponse : to handle response {"id","attributes"}