HTTP Json requests in C++? - c++

How to make HTTP Json requests in C++? Any library? Under "HTTP Json request" I mean make POST with Json object as data and receive result as Json.

Use libCURL to get the actual JSON data. Then parse it with some C++ library like jsoncpp.

Related

415 unsupported media type content-type application/pgp-encrypted while sending POST message

I'm working in REST API development project. The client have provided the OpenAPI specification for the API which they are expecting.
We have used the openAPI generator cli to generate the API from the OpenAPI specs given by the client.
Following are the two APIs
1. /requestFile:
This API is expected to accept JSON payload and produces payload of content type application/pgp-encrypted.
We have annotated the API as below.
#postmapping(value="/requestFile",consumes={"application/json"},produces={"application/pgp-encrypted"})
The expectation is to transfer a PGP encrypted JSON file as a response to the POST message.
I'm not sure how to transfer the PGP encrypted file as a response, I have searched for some references but most of them are using maultipart file to transfer binary files. Whereas the content type of multipartfiles is not same as "application/pgp-encrypted".
I need some help in transferring this pgp encrypted file as a response to the POST message via REST API.
2. /feedback
This API consumes payload of type application/pgp-encrypted and produces a simple http response code back to the client. We have annotated the API as below.
#postmapping(value="/feedback", consumes={"application/pgp-encrypted"})
When I try to send a POST message using POSTMAN with content type application/pgp-encrypted, we are getting a 415 unsupported mediatype error.
I need to understand how do we send pgp-encrypted file as a payload via POSTMAN and what is the content type I must use to achieve this.

How to get POST multipart/form-data data before sending the request with libcurl in C++?

I'm making a POST multipart/form-data request using libcurl in C++. Before making the request, I need to calculate a cryptographic hash from the multipart/form-data encoded POST data.
My problem is I don't know how to get this data, and it is even more difficult because I have to get it before actually making the request.
Is it possible to get the POST data that libcurl encodes when you ask it to use multipart/form-data encoding? If not, is it possible to manually do the multipart/form-data encoding and ask libcurl to use it?

convert JSON input to form-data in AWS application gateway

Our old legacy APIs accept the data only in form-data format, but I am required to send my data as JSON in body of request. So, how I can convert my JSON (application/json) input to form data in AWS Application gateaway.
I have input parameter like this
{"key1": "val1", "key2": "val2"}
I tried many solution with template mapping and query string parameter but they didn't work for me maybe I am doing something wrong. Above configuration is fully supporting form-data.
Note: Due to some reason I don't want to change my legacy django code to handle JSON input instead of form data.
I would suggest looking at the structure of a raw POST form-data request. Then you should be able to structure the Integration Request to fit the form-data format using the right Content-Type and mapping template.
There is an example for GET and an example for POST on this page (with the caption "the HTTP request looks like this") https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Forms/Sending_and_retrieving_form_data

How to access a JSON webservice in Clojure?

What is the common way of accessing a web service and getting response JSON as Clojure maps ?
Do we have to use Java's java.net.URLConnection and Some JSON library like GSON ?
Is http-kit the most used library for this purpose, thats what I get via Google?
Take a look at clj-http. One of its dependencies is a JSON library called cheshire.
Here's an example of a basic GET request that parses the body as JSON.
(clj-http.client/get "http://example.com/foo.json" {:as :json})
For asynchronous HTTP you should look at http.async.client

Equivalent of URLDownloadToFile for JSON

URLDownloadToFile downloads the HTML data of the URL but I have a URL that has JSON data. Is there a function that I can use to download the data in the JSON URL?
ie. How can I download the data in this JSON URL .
I am not sure whether there is a built-in function to do so. But I believe JsonCpp may help you to parse json data.