Search code examples
apirestmicroservices

REST API for sending files between services


I'm building a microservice which one of it's API's expects a file and some parameters which the API will process and return a response for.
I've searched and found some references, mostly pointing towards form-data (multipart), however they mostly refer to client to service and not service to service like in my case.
I'll be happy to know what is the best practice for this case for both the client (a service actually) and me.


Solution

  • I would also suggest to perform a POST request (multipart) to a service endpoint that can process/accept a byte stream wrapped into the provided HTML body(s). A PUT request may also work in some cases.

    Your main concerns will consist in binding enough metadata to the request so that the remote service can correctly handle it. This include in particular the following headers:

    • Content-Type: to provide the MIME type of the data being transferred and enable its proper processing.
    • Content-Disposition: to provide additional information about the body part such as the file name.

    I personally believe that a single request is enough (in contrast to @Evert suggestion) as it will result in less overhead overall and will keep things simple (and RESTful) by avoiding any linking (or state) between successive requests.