question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Sending JSON payload to API in POST body

See original GitHub issue

I have noticed that when I call my endpoints, like so:

import { endpoints } from "wildcard-api/client";

// in some async function
const response = await endpoints.saveNewCronJob({ newCronJob: editingCronJob });

I’m getting a request being sent out that looks like this:

http://localhost:8080/wildcard/saveNewCronJob/%5B%7B%22newCronJob%22%3A%7B%22id%22%3A%22%22%2C%22payloadType%22%3A%22TEXT%22%2C%22payload%22%3A%22%22%2C%22title%22%3A%22%22%2C%22timezone%22%3A%22Etc%2FGMT%22%2C%22endpointType%22%3A%22PUBSUB%22%2C%22endpoint%22%3A%22http%3A%2F%2Flocalhost%3A8080%2Ftest-cron-endpoint%22%2C%22enabled%22%3Afalse%2C%22description%22%3A%22%22%2C%22dateUpdated%22%3A%22json-s%3AtYpE%7CDate%7C2019-03-05T14%3A05%3A14.498Z%22%2C%22dateCreated%22%3A%22json-s%3AtYpE%7CDate%7C2019-03-05T14%3A05%3A14.498Z%22%2C%22crontab%22%3A%220%200%201%2F24%20*%20*%20*%22%7D%7D%5D

This indicates that the JSON is being serialised and set in the request url as a query string. While this is fine for small payloads, when things get large things might not work out too well (https://stackoverflow.com/questions/32763165/node-js-http-get-url-length-limitation).

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:17 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
brilloutcommented, Oct 16, 2019

There is nothing to check out 😃 Just update to v0.7.x and leave your code as it is. (Or simply keep v0.5.x.)

1reaction
brilloutcommented, Jul 21, 2019

(I didn’t forget about this. I’m on vacation. Ttyl.)

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I post JSON to a REST API endpoint? - ReqBin
To post JSON to a REST API endpoint, you must send an HTTP POST request to the REST API server and provide JSON...
Read more >
How should I pass json data in the request payload of http ...
Most requests the client application (an Electron app) will be sending contains JSON-based bodies, with the only exception being multipart ...
Read more >
JSON Payload for POST Request - R-bloggers
Starting with JSON body because this is the way that most API documentation will give you the payload examples. Send the body as...
Read more >
Add a Request Body to a POST Request | API Connector
Enter a Request Body​​ As part of a POST , PUT , or PATCH request, a data payload can be sent to the...
Read more >
Sending JSON HTTP Request Body in Terminal - Baeldung
HTTP requests for verbs such as POST, PUT, and PATCH optionally sends a request body payload as part of the request.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found