Support various API Response Structures by allowing a callback to format Data
See original GitHub issueCurrently 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:
- Created 4 years ago
- Comments:7 (6 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I opened a PR, your feedbacks are welcome @olivergiess @kiaking 👍
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