Skip to main content

REST-like HTTP POST request with JSON [Resolved]

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)


Question Credit: Basile Starynkevitch
Question Reference
Asked April 16, 2019
Tags: rest, http, linux
Posted Under: Programming
41 views
1 Answers

Your Answer