Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checksums in REST API responses

Tags:

rest

php

api

Is it a good idea to send a checksum with the content of the response? And if so, what is the most common way to calculate the checksum?

Example:

HTTP/1.1 200 OK
Date: Thu, 30 Jun 2011 21:32:20 GMT
Server: Apache
Connection: close
Content-Type: application/json

22 
{test:1}
like image 736
clarkk Avatar asked Jun 30 '11 21:06

clarkk


People also ask

What is checksum used for?

A checksum is a value that represents the number of bits in a transmission message and is used by IT professionals to detect high-level errors within data transmissions. Prior to transmission, every piece of data or file can be assigned a checksum value after running a cryptographic hash function.

Can we use JSP with REST API?

Sending REST API calls from JSP tags? We can use JSTL tags to do external api calls. The tags are reusable and do not require you to litter code inside jsp. The response from the api call is added to var attribute which can be access later in the jsp file.


3 Answers

The underlying protocol for HTTP is TCP which already has a checksum mechanism, so I think it would be useless.

If you still need this kind of thing you could calculate a SHA1 signature of the body content and include it as a custom header in your response, something like

HTTP/1.1 200 OK
Date: Thu, 30 Jun 2011 21:32:20 GMT
Server: Apache
Connection: close
Content-Type: application/json
X-Checksum: 40325305549f7a09edb51ff8df9528ffd8434ac6
like image 81
Fabio Avatar answered Sep 28 '22 01:09

Fabio


You could always use the Content-MD5 header (see RFCs 2616 & 1864).

like image 34
cmbuckley Avatar answered Sep 27 '22 23:09

cmbuckley


For what? Basically TCP pretty much handles that for you (since it's supposed to be a reliable protocol), so a checksum is less necessary and arguably redundant.

However, if you were to insist on it, I'd simply add an X-Checksum HTTP header of some kind.

like image 21
Will Hartung Avatar answered Sep 27 '22 23:09

Will Hartung