Skip to content

Instantly share code, notes, and snippets.

@mariuszs
Created April 12, 2019 14:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mariuszs/c50485b8cb0f19d26a82730bb8390d60 to your computer and use it in GitHub Desktop.
Save mariuszs/c50485b8cb0f19d26a82730bb8390d60 to your computer and use it in GitHub Desktop.
package com.example.restdemo;
import java.util.Arrays;
import java.util.List;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
@RestController
@RequestMapping("/task")
public class TaskController {
public static void main(String[] args) {
SpringApplication.run(TaskController.class, args);
}
@GetMapping
public ResponseEntity<List<Task>> getTasks() {
return new ResponseEntity<>(Arrays.asList(new Task(), new Task()), HttpStatus.OK);
}
@GetMapping(value = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Task> getTaskById(@PathVariable String id) {
return new ResponseEntity<>(new Task(), HttpStatus.OK);
}
public class Task {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment