--- /dev/null
+buildscript {
+ repositories {
+ mavenCentral()
+ }
+ dependencies {
+ classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.5.RELEASE")
+ }
+}
+
+apply plugin: 'java'
+apply plugin: 'eclipse'
+apply plugin: 'spring-boot'
+
+jar {
+ baseName = 'rest-example'
+ version = '0.0.1'
+}
+
+repositories {
+ mavenCentral()
+}
+
+sourceCompatibility = 1.8
+targetCompatibility = 1.8
+
+dependencies {
+ compile("org.springframework.boot:spring-boot-starter-web")
+ testCompile("junit:junit")
+}
+
+task wrapper(type: Wrapper) {
+ gradleVersion = '2.3'
+}
--- /dev/null
+package rest;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class Application {
+
+ public static void main(String[] args) {
+ SpringApplication.run(Application.class, args);
+ }
+}
--- /dev/null
+package rest;
+
+import java.util.concurrent.atomic.AtomicLong;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.springframework.http.HttpStatus;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.ResponseStatus;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+@RequestMapping("/api/cars")
+public class CarController {
+
+ private static final String template = "Car: %s";
+ private final AtomicLong counter = new AtomicLong();
+
+ @RequestMapping(produces = { "application/json" }, method = RequestMethod.GET)
+ @ResponseStatus(HttpStatus.OK)
+ public List<Car> cars() {
+ final List<Car> cars = new ArrayList<>();
+ cars.add(new Car(counter.incrementAndGet(), String.format(template, 1)));
+ cars.add(new Car(counter.incrementAndGet(), String.format(template, 2)));
+ cars.add(new Car(counter.incrementAndGet(), String.format(template, 3)));
+
+ return cars;
+ }
+
+ @RequestMapping(value = "/{id}", produces = { "application/json" }, method = RequestMethod.GET)
+ @ResponseStatus(HttpStatus.OK)
+ public Car car(@PathVariable("id") long id) {
+ return new Car(counter.incrementAndGet(), String.format(template, id));
+ }
+}