#are you sure your doing a POST request
1 messages · Page 1 of 1 (latest)
```const url = new URL(/api/session, 'http://localhost:3000');
const body = JSON.stringify({
productId: productId
});
const requestInit: RequestInit = {
method: 'POST',
body,
cache: 'no-store',
}
requestInit.headers = new Headers({
'organizationId': organizationId,
'Content-Type': 'application/json'
});
const request = new NextRequest(url, requestInit);
const response = await fetch(request);```
That's in page.tsx
And the route endpoint:
export async function POST(request: Request) {
const body = await request.json();
const headers = {
'Authorization': request.headers.get('Authorization'),
'OrganizationId': request.headers.get('organizationId'),
'Content-Type': `application/json`
};
const res = await fetch(`...`, {
method: 'POST',
headers,
body: JSON.stringify(body)
});
const session = await res.json();
return NextResponse.json(session);
}
Forgive me since uh
I am not familiar with creating NextRequest and passing stuff to it but um
I tried changing to just a Request, same result
cant u do
await fetch(url, {
cache: 'no-store',
method: "POST",
body: JSON.stringify({productId}),
headers: {
organizationId: organizationId,
"Content-Type": 'application/json'
}
})
i havent done a post with fetch in a minute
it seems to work. And I do prefer the your way. But what's the difference? Can't spot it
Not sure anymore but I realize what youre saying now. I thought it took a Reuqest though, and that seems to be incorrect as well
Thanks a lot!
Very strange thing though.. is that it worked? I was investigating why it was hitting cache as I thought POST requests weren't cached..
ur post request is hitting a cahce right now?
It was yes, but not with cache: 'no-store'