Has adonis something like Laravel API Resources?


hello guys, how are you?
I was looking for a way to return my models data formatted to my API Endpoints.

I am a laravel developer and there we use the ‘Resources’ which is a great way to format all my data before the response get sent to the client.

so if my model has fields like:

  • $name
  • $surname
  • $picture_id
  • $role_id
  • $created_at

I can use an API Resource to print

  • fullname ($name & surname)
  • picture ($picture->url)
  • role name ($role->name)
  • member since ($created_at)

has Adonis anything similar, so i dont need to format my data inside the controller before sending it to he browser/client?

Laravel API Resources: https://laravel.com/docs/5.7/eloquent-resources


Have you read the adonis js docs?


Yeah @virk rk, sorry, but i did and i didn’t found anything similar to this, or, at least it is not clearly specified.


I saw the mutators, thats really nice, but i dont realized how can i perform some actions, like get related models fields and modify them before sending the response, i’m saying, to send technically a new object, paginated, and with all that features.

Is this my question, and if adonis hasn’t this feature, i’m interested to contribute in its building.


We use serializers for that https://adonisjs.com/docs/4.1/serializers


I’m looking for that now, dont understood it at all, but i’m trying to realize how can i use it heheh.


what i understood, it will format the model data everytime that the model is instantiated, and i’m not sure if is this what i want. :sweat:


@NeroOficial Try using https://github.com/rhwilr/adonis-bumblebee

I belive this could help you. It’s very nice provider… I’m using it by default on each adonis project


Thank you @hlozancic, i was reading the bumblebee docs and seems like what i was looking for.


in addition in some cases you can use mutators to manipulate your data