What is the use of @Produces("application/pdf") in real time ?

Roshni Prasad

Roshni Prasad

@roshni-prasad-GAhUza Oct 26, 2024
While going through the basics of rest web services I have seen the use of Download Files from (JAX-RS) RESTful Web Service.
Can some one please let me know the actual use of
@Produces(“text/plain“)
@Produces(“image/your image type[.jpg/.png/.gif]”)
@Produces(“application/pdf“)

Replies

Welcome, guest

Join CrazyEngineers to reply, ask questions, and participate in conversations.

CrazyEngineers powered by Jatra Community Platform

  • Jason Estibeiro

    Jason Estibeiro

    @jason-IQjfPQ Mar 22, 2016

    The #-Link-Snipped-# annotation is used to specify the MIME media types of representations a resource can produce and send back to the client. Also, in the response sent back to the client the response header `Content-Type` is set to the MIME type passed to the annotation.

    So,
    @Produces(“text/plain“) 
    will generate a response which will contain just plain text.

    @Produces(“application/pdf“)
    will generate a response with a document in .pdf format.

    This documentation #-Link-Snipped-# has explained it very well. Do have a look at it.
  • Roshni Prasad

    Roshni Prasad

    @roshni-prasad-GAhUza Mar 28, 2016

    Jason Estibeiro
    The #-Link-Snipped-# annotation is used to specify the MIME media types of representations a resource can produce and send back to the client. Also, in the response sent back to the client the response header `Content-Type` is set to the MIME type passed to the annotation.

    So,
    @Produces(“text/plain“) 
    will generate a response which will contain just plain text.

    @Produces(“application/pdf“)
    will generate a response with a document in .pdf format.

    This documentation #-Link-Snipped-# has explained it very well. Do have a look at it.
    Hi Jason,
    Thanks for the reply.
    I would like to tell you that I am aware of the basic usage of @Produces.
    What I wanted to know is can we use @Produces(“application/pdf“) in-order to convert a java object to PDF file?