Thomas Spycher
Thomas Spycher

Reputation: 976

Restful API serve Images

I wonder which is the better way to serve images trough a Restful API.

Either:

a) serve the image as base64 and build an image in javascript in the browser and display it with data-url

or b) serve a url to retrieve/display the image

As far as i understand these methods, both are allowing the browser to cache the images.

Upvotes: 4

Views: 5405

Answers (1)

Manmay
Manmay

Reputation: 854

I will suggest the 2nd option - server a url to retrive an image. A REST service can support different MIME types , in your case it can be image/* . Secondly it is not always necessary that consumer of your REST service will be a JS app, your REST endpoint can be embedded in any static or dynamic webpage to render the image. Thirdly, it will be easier to access or test your endpoint with the 2nd approach.

Upvotes: 4

Related Questions