I have online store and writing REST API now.
I cannot choose the best way of building API methods and responses.
I have following url to access product
I need to have ability to specify width and height of image in REST request, so I have already asked this question and advice was to use something like this
mysuperstore.com/api/categories/40/products/53/image?width=100&height=100
This looks really better than previous example.
But now my question is how to retrieve image correctly without sending tons of request.
What do I mean ?
mysuperstore.com/api/categories/40/products/53/image?width=100&height=100
In this url we are set desired dimension, what response should be than ?
It should be image or it should url to image ??
I think it is better to have url of image rather than getting raw image each time.Maybe I am wrong ,please correct me.
So if this method will return url we should make another request to download image.
In this case we have two requests to retrieve image.
I though about setting image url in response to this url
mysuperstore.com/api/categories/40/products/53
In JSON format
{
"name": "HTC One",
"id": "1",
"image_url": "http://mysuperstore.com/images/htc-one.png"
}
In this case we will get raw image without any resizing.
There is possible url to get resized image and data in one request.
mysuperstore.com/api/categories/40/products/53?width=100&height=100
But it seems weird and unclear even for me.
I cannot get how to build this API elegantly without making it redundant.
Please suggest what is the most correct way to follow in this case.
Thank you.