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

Request body is omitted from POST requests in Next.js #2111

Open
1 task done
corydeppen opened this issue Jan 23, 2025 · 3 comments
Open
1 task done

Request body is omitted from POST requests in Next.js #2111

corydeppen opened this issue Jan 23, 2025 · 3 comments
Labels
bug Something isn't working openapi-fetch Relevant to the openapi-fetch library

Comments

@corydeppen
Copy link

openapi-fetch version

0.13.4

Description

I'm trying to use openapi-fetch in a Next.js 14 app and I've noticed the body is being omitted from POST requests made from within server functions and RSCs. Specifically, prior to calling new CustomRequest(), requestInit.body contains the expected serialized/stringified object, however it's missing from the request instance that's created.

Admittedly, I haven't tried this in a different framework yet, so I'm not entirely sure whether this could be related to Next.js at this point. I just wanted to include that context in case it helps.

Reproduction

Make a POST request from a server function or RSC and observe the API request will be made without a body.

Expected result

Fetch requests containing a body that are made via openapi-fetch should pass the serialized data to the API as a standard fetch request would.

Extra

@corydeppen corydeppen added bug Something isn't working openapi-fetch Relevant to the openapi-fetch library labels Jan 23, 2025
@kerwanp
Copy link
Contributor

kerwanp commented Jan 23, 2025

Hi @corydeppen,

I haven't tried using Next 14 but I haven't encountered this issue with Next 15. Could you provide a minimal reproducible example?

@corydeppen
Copy link
Author

@kerwanp After digging some more, my issue seems to be related to how fetch is called in my app. Before using openapi-fetch, I had been passing body as a part of the options object that's given to fetch (e.g. fetch(url, options)). I noticed that openapi-fetch is creating a Request and passing that to fetch instead (e.g. fetch(Request)). I'm wondering if the API (Azure Logic Apps) that's being called by my app isn't able to read the body/stream when the Request instance is used by fetch.

@corydeppen
Copy link
Author

I recognize it doesn't exist today, but would it be feasible in the future to pass the options directly to fetch as the second arg instead of creating a request and passing that to fetch in cases where a custom Request isn't specified when the client is created? I don't know how common it is for APIs to be unable to read the body when it's a ReadableStream.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working openapi-fetch Relevant to the openapi-fetch library
Projects
None yet
Development

No branches or pull requests

2 participants