Reputation: 2953
In restfull WS, how to tell client to send only csv and text format file.
In content-type
header, client set the format in which it is sending request and in Accept
header, client set the format in which it want to accept response.
But how to tell client to send only content-type
csv or file ? Is this through some documentation ?
Upvotes: 2
Views: 666
Reputation: 441
if i develop a restful application using spring i would set the produces attribute to return csv or plain text ( https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/bind/annotation/RequestMapping.html) . if the client tries to request a resource other than csv or text it will recieve an error . probably 415
Upvotes: 0
Reputation: 131037
The 415
status code seems to be suitable for this situation:
The
415
(Unsupported Media Type) status code indicates that the origin server is refusing to service the request because the payload is in a format not supported by this method on the target resource. The format problem might be due to the request's indicatedContent-Type
orContent-Encoding
, or as a result of inspecting the data directly.
The response payload could contain a list of the media types supported by the server.
Upvotes: 3
Reputation: 6742
Image you have an endpoint called /textfiles
- the developer using your API is usually reading your documentation on how to implement this endpoint. Unless you're not doing some auto-discovery magic (which I guess is still not common).
If we take Facebook for example, they just state in their documentation which files you can send:
We accept the following files: 3g2, 3gp, 3gpp, [...]
Your question:
But how to tell client to send only content-type csv or file ?
is also a bit unclear. When the user has sent the request, he already attached the files he thought he could send. So here you would rather send an error with a message, which files are allowed. So are we talking about some "pre"-requests here?
From a backend developers point of view I can just tell you: It's in the documentation. Handle errors properly, document and your implementing developer will not hate you :)
Upvotes: 0