I am new to REST API design and I have two questions about the API I am trying to write.
I want to create a service that, giving a PDF file encoding, creates an object in the database.
My current service looks like this:
@RequestMapping(value = "/create", method = RequestMethod.POST,
produces = MediaType.APPLICATION_JSON_VALUE,
consumes = MediaType.APPLICATION_OCTET_STREAM_VALUE)
public String create(@RequestBody byte[] pdf)
My questions are:
- Is it "recommended" to use the byte[] with REST APIs ? PS: the service will be consumed by web clients as well as toolkits.
- I tried to use springfox to document my API. the UI tool does not allow me to submit binary data.
I used the following annotation
@ApiImplicitParams({
@ApiImplicitParam(name = "pdf", value = "PDF encoding", required = true,
allowMultiple = true,
paramType = "body", dataType = "byte")
})
The generated JSON is:
{"type":"array","items":{"type":"string","format":"byte"}}
However the UI interface displays a textarea for the PDF encoding and submits any content as a string. (For example, if I submit the value "5", the server receives [53]).
Do you have any idea what I am missing at this level ?
-- EDIT --
The PDF is generated in the client side from an HTML form. So it is not a simple form submit.