halson | The HALJSON Resource Object | JSON Processing library
kandi X-RAY | halson Summary
kandi X-RAY | halson Summary
The HAL+JSON Resource Object.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of halson
halson Key Features
halson Examples and Code Snippets
Community Discussions
Trending Discussions on halson
QUESTION
I'm actually trying the power of react-ketting with a fastify's API.
From the hook useResource, I can get a submit function that will make a POST but I can't know when that submit is done and I can't get the API reply of this POST.
React doesn't allow this? Did I miss a param or must I use something else for PUT/POST like axios in order to have all control ?
...ANSWER
Answered 2021-Apr-12 at 15:53There's two main reasons/processes to do POST requests with Ketting.
- To create a new resource / add a new resource to a collection.
- To do an arbitrary RPC call / submit a form.
When you use the useResource()
hook, and use the submit()
function, the primary purpose of this is to deal with the first case.
Because you are strictly making a new resource, the expectation is that the response contains:
- A
201 Created
status - A
Location
header pointing to the newly created resource.
Optionally, you the server can return the body of the newly created resource, but to do that, the server must also include a Content-Location
header.
If that was your purpose, you can get the result of the POST
request simply by listening to state changes in the component you already have.
If you are in the second category and just want to do an arbitrary POST request and read the response, you should not use the submit()
function returned from the hook.
The submit()
function on the useResource
hook is really used as a 'resource state submissions' mechanism, and it's not good to overload this for other arbitrary POST
requests.
Instead, just use the .post()
function on the Resource
itself.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install halson
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page