1. Domino REST
  2. Rest clients
  3. Multipart forms

Multipart forms

Multipart params

For defining a multipart form data, the content type of the request should be multipart/form-data. Once domino-rest finds out that this request is a multipart form data request, it will try to search for javax.ws.rs.FormData fields which indicates the parts of the request. Example

			@RequestFactory
public interface MoviesService {

    @Path("library/movies/:movieName")
    @GET
    Movie getMovieByName(@PathParam("movieName") String movieName);

    @Path("library/movies")
    @GET
    List<Movie> listMovies();

    @Path("library/movies/:name")
    @PUT
    @SuccessCodes({200})
    void updateMovie(@beanParam @RequestBody Movie movie);
}

		

This will generate a request with two parts, one contains the id and the other contains the binary content of the file with a name file.

Sending JSONs

When sending objects that has ObjectMapper, domino-rest uses domino-jackson to serialize the object into JSON and use if for the form data. Same goes when defining a javax.ws.rs.FormData that has a serializable object as follows:

			MoviesServiceFactory.INSTANCE
    .getMovieByName("hulk")
    .onSuccess(movie ->{})
    .send();

		

The SampleObject will be sent as a json inside the part sampleObjectJson.

Multipart context

Sometimes, multipart form data request has a lot of parts, these parts can be grouped using @Multipart as follows:

			@Path("second-root-path")
public interface SecondService {
    @Path("second-path")
    SomeResponse secondRequest();
}

		

Where the SampleMultipartRequest is defined like this:

			import javax.ws.rs.FormParam;

public class SampleMultipartRequest {

  @FormParam("sampleObjectJson")
  private SampleObject sampleObject;

  @FormParam("file")
  private byte[] fileContent;

  @FormParam("size")
  private int size;

  public SampleObject getSampleObject() {
    return sampleObject;
  }

  public void setSampleObject(SampleObject sampleObject) {
    this.sampleObject = sampleObject;
  }

  public byte[] getFileContent() {
    return fileContent;
  }

  public void setFileContent(byte[] fileContent) {
    this.fileContent = fileContent;
  }

  public int getSize() {
    return size;
  }

  public void setSize(int size) {
    this.size = size;
  }
}

		

We are a group of passionate people who love what we do

Donate & Support Us