I am coding a poof-of-concept throw-away GCC plugin (see this for more context) which would use the HTTP 1.1 protocol to interact with my Bismon (GPLv3+ code on github, but unreleased; draft technical report here) system (which provides some Web & HTTP service using libonion). Both server and client are on the same trusted local area network (so insecurity concerns related to HTTP vs HTTPS are out of scope).

In my limited understanding, my GCC plugin would be some RESTful client (however, I don't fully understand yet what that exactly means). Morally that plugin is doing some kind of RPC (or even JSONRPC) using HTTP transport.

That plugin will use the libcurl easy interface and make a POST request, inspired by this example. For good internal reasons, I would prefer the data sent in that request (from plugin to bismon) to be some JSON encoded data and I will use the json-cpp library in that plugin.

It is obviously simpler to me to send, as CURLOPT_POSTFIELDS, the entire JSON object and avoiding encoding it a second time as application/x-www-form-urlencoded MIME type.

Is it reasonable to do so, so just send an application/json data in the POST request?

Most examples I see are using application/x-www-form-urlencoded

And I might later want to do some similar REST-like request using the curl command. Then should I use something like curl -b "BISMONCOOKIE=n000001R3dDxLtW8g_1pHEXatdVWO" -d '{"x":1,"y":2}' -H 'Content-Type: application/json' http://localhost:8086/ or should the -d be replaced by --data-raw ?

PS. Bismon already has the code for serving HTTP POST requests using libonion, and I would like to reuse the same code (for HTTP requests coming from my GCC plugin thru libcurl, not from a real browser like Firefox)

  • If the server accepts "application/json", yes.
    – Laiv
    Apr 12, 2019 at 14:45

1 Answer 1


Yes, sending POST requests as application/json with the body being a JSON object is common in REST and REST-like interfaces over HTTP.

In fact, sending a Content-Type header of application/json for an HTTP request is often how a client communicates to a REST-like web service that the request body should be expected to be formatted as JSON. This is referred to as content-negotiation.

  • And what about curl as in my edited question? -d or --data-raw ? Apr 12, 2019 at 14:05
  • 1
    It looks like --data-raw can be used when you provide the body inline, as in your example. If you want to provide the POST body from a file, you can use e.g. -d @some-filename.json. Apr 12, 2019 at 14:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.