I'm constructing restful API URLs to get products data. So I have,
POST /products
GET /products
GET /products/{:id}
DELETE /products/{:id}
One of requirement is to provide endpoints to get product data in JSON for exporting to different file format, CSV and PDF. It will be called by other service (export service).
Example of the response:
for PDF
{
products_pdf: {
title: 'Products',
sub_title: 'as per May 20 2018',
products: [
{
name: 'product A',
},
{
name: 'product B',
}
]
}
}
for CSV, simpler response than PDF. Based on requirement, both can't be served in one response.
{
products_csv: [
{
name: 'product A',
},
{
name: 'product B'
}
]
}
What is the proper restful URL endpoint for it?
I'm thinking of like
GET /products/exports/{:file_format}
GET /products/exports/csv
GET /products/exports/pdf
For me, the format of the data is optional and as such should not dictate the resource endpoint. The most logical solution to me would be to have a default format and use a query string parameter to override e.g.
GET /products?format={pdf|csv}