npm.io
1.2.2 • Published 4 years ago

strapi-parse

Licence
MIT
Version
1.2.2
Deps
0
Size
6 kB
Vulns
0
Weekly
0
Stars
4

Version

strapi-parse

strapi-parse is an NPM package that can be used to parse Strapi V4 API responses into easier to work with objects.

Usage

$ npm i --save strapi-parse
import { strapiParse } from "strapi-parse";

const parsedAPIResponse = strapiParse(strapiAPIResponse);

Examples

strapi-parse does not currently support getting data from the meta properties

Collection Type
// Strapi API Response
{
  data: [
    {
      id: 1,
      attributes: {
        title: "Test Article",
        slug: "test-article",
        // ...
      }
    },
    {
      id: 2,
      attributes: {
        title: "Test Article 2",
        slug: "test-article-2",
        // ...
      }
    }
  ],
  meta: {
    // ...
  }
}

// strapi-parse Output
[
  {
    id: 1
    title: "Test Article",
    slug: "test-article",
    // ...
  },
  {
    id: 2
    title: "Test Article 2",
    slug: "test-article-2",
    // ...
  }
]
Single Type
// Strapi API Response
{
  data: {
      id: 1,
      attributes: {
          title: "Test Article",
          slug: "test-article",
          // ...
      },
      meta: {
          availableLocales: []
      }
  },
  meta: { }
}

// strapi-parse Output
{
  id: 1
  title: "Test Article",
  slug: "test-article",
  // ...
}

Author

Joshua Henry - @jch-code

License

MIT License