Code Monkey home page Code Monkey logo

jaxrs-sample-jersey's Introduction

JAX-RS Sample : Jersey version

Build Status

Overview

Sample project for testing JAX-RS 2.0 with Jersey 2.x

Project generation

Maven archetype used :

mvn archetype:generate -DarchetypeGroupId=org.glassfish.jersey.archetypes -DarchetypeArtifactId=jersey-quickstart-webapp -DarchetypeVersion=2.25.1 -DgroupId=fr.husta.test.jaxrs -DartifactId=jaxrs-sample-jersey -B

Run

Run the webapp with :

mvn jetty:run
Note
Jetty 9 needs Java 8 !

REST with JAX-RS

What is the use of certain HTTP headers ?

Request Headers

HTTP Header Use JAX-RS Annotations Example

Accept

Used to set the preference for the content type of the response body. Can have multiple values. If unsuitable, server will send a HTTP 406.

@Produces

application/json,application/xml

Content-Type

Used to precise the content type of the request body.

@Consumes

application/json

Response Headers

HTTP Header Use JAX-RS Annotations Example

Content-Type

Used to precise the content type of the response body. No header if no content.

Depends on @Accept and Content negotiation

application/json

JAX-RS with Jersey

I use Jersey as the JAX-RS implementation.

Up to Jersey 2.25, Java 6 and JAX-RS 2.0 (JSR-339) are required.

As of Jersey 2.26, there are important changes :

  • Requires Java 8

  • Use JAX-RS 2.1 (JSR-370)

Docker

Build an image

docker build -t jaxrs-sample-jersey .

Run a container

docker run -d –name jaxrs-test-1 -p 8090:8080 jaxrs-sample-jersey

Test

Or try :

curl -X GET http://localhost:8090/jaxrs-sample-jersey/webapi/myresource[http://localhost:8090/jaxrs-sample-jersey/webapi/myresource]

Generated with Asciidoctor 2.0.22

jaxrs-sample-jersey's People

Contributors

ghusta avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.