Simple Post to Workers - bodies/headers disappearing

Hi, Simple Post to Workers is creating nightmare- the post bodies/headers with simple JSON disappear, locked=false show up. I understand the redirects and all that, but why is it not as robust as google functions - where everything stays in place?

Hi, anyone has similar issue. I had to end up passing lot of the information to the query string of the URL, so I do not have the JSON body that I keep losing when sending to workers. Since there is a limit as to how much data I can attach to the URL query sting example: https://sample1.example.workers.dev?name=John&profileimagehtmlsafe=AFEJHEiwoMGDCBMqXMiwocAbBww4nEhxoYkUpzJGrMixogkfGUNqlNix I am looking for help. Thanks!

It is not overly clear what you mean by that in the first place.

If you send a POST request to a Worker, the Worker will be able to access the request body and nothing will disappear.

You probably need to elaborate on your issue and provide a live example.

Hi, thank you.
I have this published example: Read POST

I just copy and paste this into my workers and get the workers.dev url.
I then go to POSTMAN and select POST verb and in the body RAW I add this
{โ€œaโ€:โ€œa1โ€}

It is not able to read this Json.

Thanks!

As you can see from my example JSON is properly handled. You might have to adjust your code.

Ok Thanks a lot. I will start with your example and add code to that. Have a great day.

Just pay attention to the content type you are sending, as that could influence how your request is handled on the server side. Though that would be a bit beyond the scope of the forum, so just a heads up, for JavaScript development StackOverflow and Reddit will be a better choice. https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST has more on that too.

I was probably not using the await command so getting {}
return new Response(JSON.stringify(request.json()));
instead of
return new Response(JSON.stringify(await request.json()));
Will keep testing. Thanks!

json returns a promise, not the value itself. So you either have to use await to resolve the promise or use the traditional promise approach.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.