Code Monkey home page Code Monkey logo

jaxrs-and-jersey-alura's Introduction

Build Status

JAX-RS and Jersey: REST webservices

Overview

This repository contains an example of how to implement RESTful Web Services in Java using JAX-RS and Jersey.

JAX-RS

Java API for RESTful Web Services (JAX-RS) is a Java programming language API spec that provides support in creating web services according to the Representational State Transfer (REST) architectural pattern. JAX-RS uses annotations, introduced in Java SE 5, to simplify the development and deployment of web service clients and endpoints.

From version 1.1 on, JAX-RS is an official part of Java EE 6. A notable feature of being an official part of Java EE is that no configuration is necessary to start using JAX-RS. For non-Java EE 6 environments a small entry in the web.xml deployment descriptor is required.

Jersey

Jersey RESTful Web Services framework is an open source framework for developing RESTful Web Services in Java. It provides support for JAX-RS APIs and serves as a JAX-RS (JSR 311 & JSR 339) Reference Implementation.

How to run the application

Execute the following command to deploy the application:

docker-compose up

It will available at: http://localhost:8081

The application contains two controllers, one for managing carts and their products, and another one for managing products. Below are some curl commands to reach out the operations provided by it.


Cart Operations

Create a new cart:

curl -d '{"street": "street one","city": "new york","products": [{"price": 115.9,"name": "shoes","quantity": 1},{"price": 45,"name": "t-shirt","quantity": 1}]}' -H "Content-Type: application/json" -X POST http://localhost:8081/api/carts

Find all carts:

curl -i -H "Accept: application/json" -H "Content-Type: application/json" -X GET http://localhost:8081/api/carts

Find a specific cart:

curl -i -H "Accept: application/json" -H "Content-Type: application/json" -X GET http://localhost:8081/api/carts/1

Delete a cart:

curl -X "DELETE" http://localhost:8081/api/carts/1

Delete product by id from a specific cart:

curl -X "DELETE" localhost:8080/api/carts/1/products/1

Update product quantity:

curl -X PUT -H "Content-Type: application/json" -d '{"quantity": 2}' http://localhost:8081/api/carts/1/products/1/quantity


Project Operations

Create a new project:

curl -d '{"name": "project","year": "2018"}' -H "Content-Type: application/json" -X POST http://localhost:8081/api/projects

Find all projects:

curl -i -H "Accept: application/json" -H "Content-Type: application/json" -X GET http://localhost:8081/api/projects

Find a specific project:

curl -i -H "Accept: application/json" -H "Content-Type: application/json" -X GET http://localhost:8081/api/projects/1

Delete a project:

curl -X "DELETE" http://localhost:8081/api/projects/1


Postman

The postman collection is available to be imported at: https://github.com/rafael-pieri/jaxrs-and-jersey-alura/tree/master/postman

jaxrs-and-jersey-alura's People

Contributors

rafael-pieri avatar

Watchers

James Cloos avatar  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.