Code Monkey home page Code Monkey logo

jsonapi's People

Contributors

alexandru-calinoiu avatar christophp avatar fabienhenon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

jsonapi's Issues

How to decode polimorphic relations

Given the following json

                            {
                                "data": {
                                    "id": "38",
                                    "type": "question_set",
                                    "attributes": {
                                        "position": 33,
                                        "title": "Goal 2: Zero Hunger"
                                    },
                                    "relationships": {
                                        "form_category": {
                                            "data": {
                                                "id": "6",
                                                "type": "form_category"
                                            }
                                        },
                                        "responses": {
                                            "data": []
                                        },
                                        "form_questions": {
                                            "data": [
                                                {
                                                    "id": "43",
                                                    "type": "text_area"
                                                },
                                                {
                                                    "id": "44",
                                                    "type": "text"
                                                }
                                            ]
                                        }
                                    },
                                    "links": {
                                        "self": "http://localhost:4000/v1/cops/1/questions/38",
                                        "next_question": "http://localhost:4000/v1/cops/1/questions/44",
                                        "prev_question": "http://localhost:4000/v1/cops/1/questions/32"
                                    }
                                },
                                "included": [
                                    {
                                        "id": "6",
                                        "type": "form_category",
                                        "attributes": {
                                            "position": 6,
                                            "title": "SDGs"
                                        },
                                        "relationships": {
                                            "form_questions": {
                                                "data": []
                                            }
                                        }
                                    },
                                    {
                                        "id": "43",
                                        "type": "text_area",
                                        "attributes": {
                                            "position": 4,
                                            "title": "Please use this space to describe in more detail the work you are undertaking to contribute to this Goal"
                                        },
                                        "relationships": {
                                            "form_category": {
                                                "data": {
                                                    "id": "6",
                                                    "type": "form_category"
                                                }
                                            },
                                            "responses": {
                                                "data": []
                                            }
                                        },
                                        "links": {
                                            "self": "http://localhost:4000/v1/forms/1/questions/43",
                                            "next_question": null,
                                            "prev_question": null
                                        }
                                    },
                                    {
                                        "id": "44",
                                        "type": "text",
                                        "attributes": {
                                            "position": 5,
                                            "title": "Other question type"
                                        },
                                        "relationships": {
                                            "form_category": {
                                                "data": {
                                                    "id": "6",
                                                    "type": "form_category"
                                                }
                                            },
                                            "responses": {
                                                "data": []
                                            }
                                        },
                                        "links": {
                                            "self": "http://localhost:4000/v1/forms/1/questions/44",
                                            "next_question": null,
                                            "prev_question": null
                                        }
                                    }
                                ]
                            }

How can I decode the form_questions relation? I need some way to access the type so I know what decoder to use.

Collection level links

Hi,

I can't figure out how to decode collection level links,

Like in the bellow example:

{
    "data": [
        {
            "id": "1",
            "type": "cop",
            "attributes": {
                "report_period_from": "2018-10-22T10:00:00.000+00:00",
                "report_period_to": "2018-10-22T10:00:00.000+00:00"
            },
            "relationships": {
                "form": {
                    "data": {
                        "id": "1",
                        "type": "form"
                    }
                }
            },
            "links": {
                "self": "http://localhost:4000/v1/cops/1",
                "current_question": null
            }
        }
    ],
    "included": [
        {
            "id": "1",
            "type": "form",
            "attributes": {
                "name": "COP seed"
            },
            "relationships": {
                "form_categories": {
                    "data": []
                }
            },
            "links": {
                "self": "http://localhost:4000/v1/forms/1"
            }
        }
    ],
    "links": {
        "create": "http://localhost:4000/v1/cops"
    }
}

I want to grab the create link

Null link will result in empty dic

Given a link is null

        {
            "id": "1",
            "type": "cop",
            "attributes": {
                "report_period_from": "2018-10-22T10:00:00.000+00:00",
                "report_period_to": "2018-10-22T10:00:00.000+00:00"
            },
            "relationships": {
                "form": {
                    "data": {
                        "id": "1",
                        "type": "form"
                    }
                }
            },
            "links": {
                "self": "http://localhost:4000/v1/cops/1",
                "current_question": null
            }
        }

When decoding this resource the links dictionary is empty, I think it will be better if null links are ignored.

Fails on relations that are not included

A resource can have a relation that might not be included in the included node

For example:

{
    "data": {
        "id": "1",
        "type": "cop",
        "attributes": {
            "report_period_from": "2020-06-15T16:35:49.433+00:00",
            "report_period_to": "2021-06-15T16:35:49.433+00:00",
            "completed_percent": 28,
            "level": "active"
        },
        "relationships": {
            "form": {
              "links": {
                   "self": "http://localhost:4000/cop/1/relationships/formr",
                   "related": "http://localhost:4000/form/1"
                },
                "data": {
                    "id": "1",
                    "type": "form"
                }
            }
        },
        "links": {
            "self": "http://localhost:4000/v1/cops/1",
            "current_question": "http://localhost:4000/v1/cops/1/questions/1"
        }
    },
    "links": {
        "create": "http://localhost:4000/v1/cops"
    },
    "included": [
    ]

The cop type has a form relationship that is not included in the response, the client can specify to include this resource or it can go fetch it when needed via the related link.

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.