Custom response data

So, I would like to know how can I custom my responde data. For example, I have a “posts” content-type which has a “author” as a field related to the user, but as a response for the author, I get a lot of data that I actually don’t want…

"author":{
         "id":1,
         "username":"user01",
         "email":"test@email.com",
         "provider":"local",
         "confirmed":true,
         "blocked":false,
         "role":3,
         "created_at":"2021-09-01T23:04:21.969Z",
         "updated_at":"2021-09-03T00:23:52.184Z",
         "avatar":{
            "id":2,
            "name":"create-pixel-art-cartoon-portrain-for-you.jfif",
            "alternativeText":"",
            "caption":"",
            "width":550,
            "height":370,
            "formats":{
               "thumbnail":{
                  "name":"thumbnail_create-pixel-art-cartoon-portrain-for-you.jfif",
                  "hash":"thumbnail_create_pixel_art_cartoon_portrain_for_you_6122d837d9",
                  "ext":".jfif",
                  "mime":"image/jpeg",
                  "width":232,
                  "height":156,
                  "size":4.83,
                  "path":null,
                  "url":"/uploads/thumbnail_create_pixel_art_cartoon_portrain_for_you_6122d837d9.jfif"
               },
               "small":{
                  "name":"small_create-pixel-art-cartoon-portrain-for-you.jfif",
                  "hash":"small_create_pixel_art_cartoon_portrain_for_you_6122d837d9",
                  "ext":".jfif",
                  "mime":"image/jpeg",
                  "width":500,
                  "height":336,
                  "size":12.4,
                  "path":null,
                  "url":"/uploads/small_create_pixel_art_cartoon_portrain_for_you_6122d837d9.jfif"
               }
            },
            "hash":"create_pixel_art_cartoon_portrain_for_you_6122d837d9",
            "ext":".jfif",
            "mime":"image/jpeg",
            "size":11.84,
            "url":"/uploads/create_pixel_art_cartoon_portrain_for_you_6122d837d9.jfif",
            "previewUrl":null,
            "provider":"local",
            "provider_metadata":null,
            "created_at":"2021-09-01T23:04:13.496Z",
            "updated_at":"2021-09-01T23:04:13.510Z"
         }
      }

So, of all this data, I would like to only show the username and the avatar for example. How could I do that?

Out of the box you can use graphql or edit the controller and just pick your fields.

1 Like

do you have a url that explains how to edit the controller or an example?

This is a great place to start