Change content-type depending on we need to edit or to create a ressource
I implemented the edit and the create possibility in my refine application. My API need the
application/json
content-type for the creation and need application/merge-patch+json
for the edition. How can set the both in my axios header (if it is possible) ?14 Replies
continuing-cyanβ’2y ago
gradual-turquoiseβ’2y ago
Thank you and can i have
application/json
for the creation and edition with the metaData
or with something else?continuing-cyanβ’2y ago
u can send
metaData
with useForm
.
you can send something different for each useForm
for example, send merge-patch+json in useForm
on your EditPage
gradual-turquoiseβ’2y ago
Ok thank you π I'm going to tried and get back to you if i have an issue π
maybe you can use axios Interceptors (https://axios-http.com/docs/interceptors)
like an authorization header -> https://refine.dev/docs/api-reference/core/providers/auth-provider/#setting-authorization-credentials
gradual-turquoiseβ’2y ago
I gonna tried both solution to see which one is better. Thank you bothπ
one last option, swizzle π
https://refine.dev/docs/tutorial/understanding-dataprovider/swizzle/
2. Create Data Provider with Swizzle | refine
What is Swizzle?
gradual-turquoiseβ’2y ago
Ok thank you πͺ
In my edit form i've done this and this error of the content type persists should i do something else or should this modification solve the probleme ?
continuing-cyanβ’2y ago
are you seeing your headers in chrome network tab ?
gradual-turquoiseβ’2y ago
yes but it still
application/json
continuing-cyanβ’2y ago
what is your dataProvider implementation ?
you need the pass headers like this
https://refine.dev/docs/api-reference/general-concepts/#metadata
gradual-turquoiseβ’2y ago
here is my custom data povider
continuing-cyanβ’2y ago
when
useForm
is edit, using update
function
you can write like this and you can delete meteData from useForm. with this way you can only write once this header
gradual-turquoiseβ’2y ago
It work !!
Thanks you @alicanerdurmaz πͺ