Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to get the updated response from client PUT #103

Open
sazyadav opened this issue Jan 3, 2023 · 3 comments
Open

how to get the updated response from client PUT #103

sazyadav opened this issue Jan 3, 2023 · 3 comments

Comments

@sazyadav
Copy link

sazyadav commented Jan 3, 2023

I need to return the updated state data with PUT response :

const put = async (url: string, data: any) => {
const client = ClientAPI.getInstance();
const resource = client.go(url);
return await resource.put({ data });

};

but getting undefined.
could you please help me to get the updated respone from the PUT request

@evert
Copy link
Contributor

evert commented Jan 4, 2023

Hi @sazyadav . In your case, does the server change what was stored and returned the updated body in the HTTP response?

We have an open ticket to support return-representation here: badgateway/ketting#22
It would be helpful to know if fixing that ticket solves your problem.

There is a workearound right now though, if your server returns the Content-Location header (pointing to itself), this will also work:

const put = async (url: string, data: any) => {
  const client = ClientAPI.getInstance();
  const resource = client.go(url);
  await resource.put({ data });
  const newState = await resource.get();
  return newState.data;
};

This will be served from cache without doing a HTTP request with your new data if the server returned Content-Location. If you didn't return this header, it will return whatever you sent with put() last.

@sazyadav
Copy link
Author

sazyadav commented Jan 27, 2023

Hi @evert , thanks for your reply.

with const newState = await resource.get();
return newState.data;
Not getting the latest submitted data.
But with the js Fetch I am getting:
const fetchForPut = async (url: string, payload: any): Promise => {
const requestOptions = {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload)
};
const response = await fetch(url, requestOptions);
return await response.json();
}

How can I acheive the same with react ketting.
and also fixinga above mentoined issue ( badgateway/ketting#22 ) would be really helpful for me.

@evert
Copy link
Contributor

evert commented Jan 29, 2023

hi @sazyadav can you edit your question to fix the formatting? it's hard to follow right now. To have syntax highlighting work code blocks need to start with

```typescript

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants