Day 19: RESTful API in Java with JAX-RS Framework

Harini Janakiraman
Jun 1, 2016 · 2 min read


It’s first of the month, so re-kickstarting the challenge with freshness after a brief break . Let’s jump right into some coding action!

Project (1 hour): Build a RESTful service using JAX-RS the JAVA API for RESTful Web Services that will service user information.

All the code for this project can be found on my github

Step 1: Installation

  • Download the latest version of JAX-RS from here.
  • Assuming you have Eclipse already installed, setup tomcat webserver using the instructions here.

Step 2: Create project

  • Create a new “Dynamic Web Project” in Eclipse, I created “RESTResourceServer”
  • Add the downloaded JAX-RS jars (from /api, /ext, /lib) into “WEB-INF/lib” directory in the project.
  • Add these jars from WEB-INF/lib into the library build path of the project by selecting “Add Jar”
  • Create a package in your project, here we create “com.resourceserver”
  • Create the following three classes, and

Note: We setup the web service using @Path annotation to UserService. Also we use the same annotation to set it to a method for UserService.

  • Create Web.xml (available in github repo link above).

Step 3: Deploy the app

  • Export the project as a “war” file and place it under webapps directory where tomcat server is installed.
  • Start the web server using tomcat

Step 4: Submit request to RESTful app

Image for post
Image for post

Day 19 of #100DaysOfCode DONE

If you enjoyed this, please click 👏 so that others can enjoy it as well. Follow me on Twitter @HariniLabs to get the latest updates or just to say Hi :)

PS: I curate a bi-weekly #WomenInTech newsletter for a dose of inspiration from the world of tech and yes men can signup too! Get it here :)

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store