Is this api response structure intentional, here to stay or customizable?

System Information
  • Strapi Version: v4.0.4
  • Operating System: Windows 10
  • Database: SQLite
  • Node Version:
  • NPM Version:
  • Yarn Version:

Hey there,
I really dislike the default response structured in object { data { id, attributes {} } }

query{
  projects{
    data{
      id
      attributes{
        name
        client{
          data{
            attributes{
              name
            }
          }
        }
      }
    }
  }
}

Simple calls are pretty verbose, and front end usage too

projects[i].client.name becomes (maybe for very valid reasons) projects[i].data.attributes.client.data.attributes.name and I don’t like it

3 Likes

I agree. I have seen similar structures in other CMS:s and it has never been good for me. I parse the responses client side and transform them to a nice flat v3 format.
I think I might write a middleware for it later on. Or maybe check if there is one alread.

I really wish this format would be optional. The data from the services is already flat. I can’t understand why it needs to be restructured like this in the controller.

1 Like

Agreed, there must be a better way for more complex data structures.

badges.filter(item => item.attributes.badge_category.data.attributes.identifier == g.attributes.identifier).map()