question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support various API Response Structures by allowing a callback to format Data

See original GitHub issue

Currently the plugin only supports a rigid API structure which does not include some of the popular standards like JSON:API given the example below for relationships.

Following JSON:API standard relationships will not be populated into models due to the response structure of the standard (see below).

{
    data: {
        id: 1,
        username: "test",
        relationships: {
            posts: {
                data: [{
                    id: 1,
                    title: "Title",
                    body: "Body",
                    user_id: 1,
                }]
            }
        }
    }
}

With the current implementation the response from the API is expected to be built for Vuex-ORM insertOrUpdate() expects an object of the following structure.

{
    data: {
        id: 1,
        username: "test",
        posts: [{
                id: 1,
                title: "Title",
                body: "Body",
                user_id: 1,
            }]
        }
    }
}

I there for suggest that we change:

  private getDataFromResponse (response: AxiosResponse, config: Config): any {
    if (!config.dataKey) {
      return response.data
    }

    return response.data[config.dataKey]
  }

To be:

  private getDataFromResponse(response: AxiosResponse, config: Config): any {
    if (!config.dataTransformer) {
      return response.data
    }

    return config.dataTransformer(response);
  }

This will allow the package to support any number of API response formats, by allowing the user to intercept and transform the response into a suitable format for Vue-ORM.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
guillaumebridaycommented, Oct 29, 2019

I opened a PR, your feedbacks are welcome @olivergiess @kiaking 👍

0reactions
kiakingcommented, Oct 31, 2019

This is now possible with Vuex ORM Axios 0.8.0! 🎉 Thanks to @guillaumebriday for the wonderful PR! https://github.com/vuex-orm/plugin-axios/releases/tag/v0.8.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

Callbacks - Swagger
In OpenAPI 3, you can define the format of the “subscription” operation as well as the format of callback messages and expected responses...
Read more >
REST API Callback - OutSystems 10 Documentation
REST API Callback. Action used to preprocess the request or to customize the response of an exposed REST API method call.
Read more >
Set up Lambda proxy integrations in API Gateway
Learn how to configure a Lambda proxy integration request and integration response in API Gateway.
Read more >
Using REST to Invoke the API | Programmable Search Engine
You can invoke the Custom Search JSON API using REST from JavaScript, using the callback query parameter and a callback function. This allows...
Read more >
What's the Difference Between OpenAPI Types 2.0, 3.0, and ...
You can define the format of the API operation as well as the callback messages and their expected responses. With OpenAPI 3.0, you...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found