Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What do I need to create a RESTful API Server in Java?

I would like to build my own RESTful API Server and I have no idea what I need for that.

I'll tell you a bit about the project:

On a Webservice (www.mysite.com/) users can register and manage their account and so on. But they also can use the RESTful API (mysite.com/api/...) and can do there pretty much the same via REST.

What is a good way to realize that? Do I need to use jetty or something similar? Should I split web service and restful api ? what I a good architecture for that?

Thanks :)

like image 484
Rob Anderson Avatar asked Mar 30 '12 12:03

Rob Anderson


People also ask

What is needed for REST API?

All client-server operations should be stateless, and any state management that is required should take place on the client, not the server. RESTful resource caching. All resources should allow caching unless explicitly indicated that caching is not possible. Layered system.


5 Answers

You can use Spring controller for building a restful server. You can run it on tomcat or jetty doesn't matter.

Check this url : http://static.springsource.org/spring/docs/3.0.0.M3/spring-framework-reference/html/ch18s02.html

like image 122
erimerturk Avatar answered Oct 20 '22 23:10

erimerturk


Tomcat and Jersey are easy to get up and running. I've had some issues with Tomcat 7 and Jersey, but with Tomcat 6 it was straight forward.

This tutorial is quite easy to follow. It's a bit old, but the principle remains the same.

like image 4
Paaske Avatar answered Oct 21 '22 00:10

Paaske


IBM provides good set of information and tutorials about building RESTful web service with Java (Link). After getting your web service running, you can deploy it to Amazon. Take a look at AWS Elastic Beanstalk.

like image 3
mert Avatar answered Oct 20 '22 22:10

mert


In 2017 one of the best solutions would be to use spring boot. Gives you great effects without writing tons of code.

@RestController
public class HelloController {

    @RequestMapping("/")
    public String index() {
        return "Greetings from Spring Boot!";
    }

}
like image 3
Marcin Szymczak Avatar answered Oct 20 '22 22:10

Marcin Szymczak


I found a simple example at http://coder2design.com/rest-web-services/ to build a REST application.

  • XML Schema(xsd) is used to build domain classes.
  • Eclipse EE is used as IDE and Maven for building.
  • Jersey as a framework for REST
  • Hibernate for persistence layer.
  • MySQL as DB

All other configurations are nicely explained.

like image 1
Jatinder Pal Avatar answered Oct 20 '22 22:10

Jatinder Pal