How much data we can send to a restapi? - json

Is there any limit on sending JSON data to a rest API?I am building an app where I have used a rest API to send an email. Here I want to send app logs to API,but before going through that I want to know about the limitation on send data to rest API.
Secondly which one is better option file or send JSON data to rest API?

In ASP.NET there's by default a 4MB limit of the size of a request. This can be adjusted using the maxRequestLength attribute on the httpRuntime element:
<httpRuntime targetFramework="4.5.2" maxRequestLength="1048576" />
In this example we set the maximum request size to be 1GB.
Secondly which one is better option file or send JSON data to rest API?
If you are planning to send large request payloads I would recommend you using the multipart/form-data content type for the request instead of JSON. This would allow you to directly send the raw bytes in the request payload. If you use JSON then you would need to encode those raw bytes to something like base64 which would make the request even larger. To even further optimize network traffic the client could gzip the raw bytes before sending them over the wire and then unzip the stream on the server.
You may also find the following article useful in setting up this file upload on the server side.

Related

Message Routing in Azure IoT Hub returning application/octet-stream

I am routing messages from an Azure IoT Hub to a blob container (Azure Storage as a routing endpoint). The messages sent to the IoT Hub are of Content Type: 'application/json' and Content Encoding: 'UTF-8'. However, when they arrive in blob storage several of these messages are batched together into one file with Content Type 'application/octet-stream'. Thus, for instance Power BI is not able to read these files in JSON format when reading directly from the blob.
Is there any way to route these messages so that each single message is saved as a json file in the blob container?
Tl;dr : Please make use of the Encoding option to specify AVRO or JSON format & Batch Frequency/Size to control the batch.
"With an Azure Storage container as a custom endpoint, IoT Hub will write messages to a blob based on the batch frequency and block size specified by the customer. After either the batch size or the batch frequency is hit, whichever happens first, IoT Hub will then write the enqueued messages to the storage container as a blob. You can also specify the naming convention you want to use for your blobs, as shown below."
The below image shows how we navigate to the IoTHub's message routing section to add a custom endpoint of a blob storage account.
-The below image shows how we configure the settings of the batch count and the size. Also please make use of the Encoding section to specify the message format such as AVRO or JSON
Please leave a comment below to let us know if you need further help in this matter.
The message encoding needs to be done by the device stream or as part of a module to translate the protocol. Each protocol (AMQP, MQTT, and HTTP) uses a different method to encode the message from base64 to UTF-8.
To route messages based on message body, you must first add property 'contentType' (ct) to the end of the MQTT topic and set its value to be application/json;charset=utf-8. An example is shown below.
devices/{device-id}/messages/events/$.ct=application%2Fjson%3Bcharset%3Dutf-8
https://learn.microsoft.com/en-us/azure/iot-hub/iot-hub-mqtt-support

How to test rest API with large json

I am writing rest api with Flask. One of my endpoints handles a post request. One field of the request JSON 'audio' is supposed to contain the BASE64 encoded PCM file (audio format). If save this field to a file, it is about 200KB.
It might be too big to copy and paste in Swagger or Postman for testing. Even worse with curl command. Is there any good way to test with really big JSON in the request.
I'd recommend a great tool called Insomnia. You can send point it to any file to send it as a HTTP request. You can change the Content-Type header to be application/json and select your JSON data file. Here's a screenshot of what the program looks like.

How to secure communication in client-server?

My application is based on AngularJS, totally client-side; the server is based on Express JS. For data communication I am using the http post method. When I send a http request, the server responds with data in JSON format, but all the JSON data shows in the client browser. I don't want to show JSON data in client browser.
Is there any way to hide or secure json data in client browser?
What ever the response you will send, will be shown at the client-end. If you want to hide some data, you can always encrypt them and send it. One of the useful tool for such is Crypto-JS.
User will still see the data but as it will be encrypted, he cannot understand it.
But, still it is safer not to send user-sensitive data to client-side.

Sending audio file into server

I'm little confused about sending audio files from my client app (max. 10 sec of audio) into my server. The question is - which of the following options is the best?
From the client side save audio file into byte array and then convert it into Base64. After that send it in json request. On the server side, handle request in a Rest Api, decode Base64 and save it on the server. I was also wondering about making hash function of the audio file from the client side and send it also with the response and from the api compare these two hashes for integrity purposes (Missing packets or something).
Send an audio file as multipart form-data in json response and handle it in my Rest Api.
Simply saving file using FTP into my server.
Which option is the best? Or do you have any ideas?

How to transfer large xml file and zip file via rest api?

I have an application which uploads a large file in the XML format and sometimes a zip file. Now I want to have that file transferred to other application via REST API. I am thinking to pass the binary data in to json response.
I have the following questions for my approach.
Is sending binary in json the best approach/practice to do it?
Will this be PUT scenario as receiver application doesn't know about new uploaded file?
If that makes it easier for the second service to consume it, I see no problem with it. You can send it on any format you want, as long as it's accepted and you're setting the Content-Type and Accept headers properly.
You use a PUT only when you're sending a complete replacement of the resource at the target URI. If you know the final URI for that and if a GET to the same URI right after the PUT will retrieve as response the same body you just submitted, it makes sense to use PUT, otherwise, use a POST.