Code Monkey home page Code Monkey logo

Comments (4)

danivek avatar danivek commented on July 18, 2024

@honestserpent, I think that the best way to do this is to serialize bands resource first. Then respond with the value of musicians's relationship.

GET example.com/v1/bands/1/relationships/musicians

Serializer.serializeAsync(bandData).then((serializedBand) => { 
return serializedBand.data.relationships['musicians'];
})

from json-api-serializer.

officer-rosmarino avatar officer-rosmarino commented on July 18, 2024

Thank you! That is extremely smart and almost perfect!!
"Almost" because doing that returns something a little bit different than what I want. In particular, it lacks top level meta and the jsonapi and linka fields.

I guess I can do it by putting that data in another object that also contains that information, like:

let serialized_data = await JSONAPISerializer.serializeAsync(bandData);
res.send(_.merge({ "jsonapi":{"version": "1.0"}}, serialized_data);

What do you think about something like this?

from json-api-serializer.

danivek avatar danivek commented on July 18, 2024

for meta and links you can define such these options on the serializer options on relationships (see doc). So you will have them in response. But you're right about jsonapi.

from json-api-serializer.

officer-rosmarino avatar officer-rosmarino commented on July 18, 2024

thanks!

from json-api-serializer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.