6

Our API will allow users to download files (10mb - 500mb).

The REST endpoint will be

/downloads/*content-id*

Where the content id is a reference to a file on our server.

I assume that the HTTP Method should be a GET, as it is trying to retrieve something. However, since I want users to be able to pause downloads to resume later, I need to also pass a bytes-received parameter to the endpoint.

Should I do this as a query param?

/downloads/*content-id*?bytesReceived=123

Or should I add the bytes-received to the request body, and if so, should I not be using GET anymore?

Also, as a second q. I am using the octet-stream content type to download the files - as I have been told this content-type will best allow me to pause the downloads and resume later. When unpacked, the file will be some HTML5 content (with js/css). Is this the best way?

Oliver McPhee
  • 1,010
  • 10
  • 18

1 Answers1

5

You should use GET method since you're getting the particular resource. You can't pass bytesReceived via body since GET does not have a body. Instead use appropriate header, it's called Range, please see here.

Opal
  • 81,889
  • 28
  • 189
  • 210
  • `You can't pass bytesReceived via body since GET does not have a body.` This is incorrect, generally it is not recommended., but body for `GET` request is allowed by the specification. Most implementation doesn't support it. So you can use if your server support and handle it correctly. See https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/GET – endo64 Aug 08 '22 at 07:11
  • Also check this debate out: https://stackoverflow.com/questions/978061/http-get-with-request-body – endo64 Aug 08 '22 at 07:14