I am developing web APIs using Spring Boot. I want one of the APIs to handle a POST request with an xml file and a few additional parameters. If it is just xml, I can just set the content-type to application/xml
. And if it is just a couple parameters, I can do param1=value1¶m2=value2
with type application/x-www-form-urlencoded
. However how do I deal with both types with one endpoint at the same time?
Asked
Active
Viewed 415 times
0

ddd
- 4,665
- 14
- 69
- 125
-
Not sure if this is what you're asking for, but you could either put the parameters to the query part of the endpoint, or use multipart content-type, see for example https://stackoverflow.com/questions/9081079/rest-http-post-multipart-with-json. It feels to me like the design change should be considered though. – František Žiačik Sep 26 '17 at 21:27
-
@FrantišekŽiačik How would you suggest I change the design? The params come from the device that is sending the request, e.g. mac address of phone. The file is generated from an mobile app. I don't think it is easy to combine both. – ddd Sep 26 '17 at 21:33
-
Depends on use case. In your case, it seems to me it should be sufficient to just use the xml content type and put the params in url. It should work fine. – František Žiačik Sep 26 '17 at 21:39
1 Answers
0
Yes, you can deal with one end-point. Just specify the correct content type on your methods.
Since you tagged sprint-boot
, I assume that you use Spring MVC? If yes, specify the proper consumes
on the RequestMapping
.

Tarlog
- 10,024
- 2
- 43
- 67
-
if I specify the content type as "application/xml" it would ignore the query params, right? – ddd Sep 26 '17 at 21:33
-
No. Request can have query parameters on url despite the content type. If you use `application/x-www-form-urlencoded` it basically means that you have query parameters in the body AND you can also have them on url. – Tarlog Sep 26 '17 at 22:33