Dealing With Files in REST API

We often come across scenarios where we need to deal with files as a part of the payload of an HTTP request or as a response. Though it is easy to do it manually in postman or swagger, it is a challenge when it comes to automation. In this article, let's see how to automate such api endpoints by sending files as a part of requests and how to download if a response is also a file.

Attach File to Request

Scalaj-HTTP is a wrapper for an HTTP client in Scala. It provides a method — postMulti to attach files as a part of a request. 

OpenAPI (Swagger) and Spring Boot Integration

Recently. while working on a requirement, there came a need to upload a file for further processing. Mostly in REST APIs, we are accustomed to using JSON input and output while it is XML for SOAP web services. 

This leads us to research how to satisfy the requirement. In Spring, and mainly in Spring Boot, the auto-configuration feature gives us big-time help even though sometimes we have to disable some features to add custom once or to change the order they are sorted in.