Mapping API Response to Data Type #589
Unanswered
ImranAhmed
asked this question in
General
Replies: 2 comments 2 replies
-
Ideally, the backend would return the keys using camelCase instead of snake_case, as a normal JSON, If that is not possible, I would wrote a function to transform the case of the data and use it inside the fetcher. const fetcher = url => fetch(url).then(res => res.json()).then(data => transformCase(data)); Something like that. |
Beta Was this translation helpful? Give feedback.
2 replies
-
I ended up mapping to my model in the api call. I am working with NextJS. This lives in
I then just use it in my application as follows:
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Looks like a nifty library.
I've now got this working.
The api call (
api/persons
) response is as follows:In my application I have a
Person
type as follows:What's the best practice for mapping the person API response to my
Person
type?Beta Was this translation helpful? Give feedback.
All reactions