Create Adding new endpoints authored by Joel Gingrich's avatar Joel Gingrich
# Adding new endpoints
Adding new endpoints is done by adding either a new controller or a new mapping in an existing controller.
Controllers are described in this article:
[[Server Components]]
Looking at the example of a controller [Server Components](Server Components#Controllers)
```java
@RestController
public class ObjectiveController {
private final ObjectiveService objectiveService;
public ObjectiveController(ObjectiveService objectiveService) {
super();
this.objectiveService = objectiveService;
}
@PostMapping("/objective-complete")
public ResponseEntity<Object> authenticateObjective(@RequestBody ObjectiveRequest request) throws JsonProcessingException {
int response = objectiveService.completeObjective(request);
ObjectiveResponse responseObj = new ObjectiveResponse(response);
return new ResponseEntity<>(responseObj.toJSON(), HttpStatus.OK);
}
}
```
Adding a GET mapping to this page would look like this:
```java
@RestController
public class ObjectiveController {
private final ObjectiveService objectiveService;
public ObjectiveController(ObjectiveService objectiveService) {
super();
this.objectiveService = objectiveService;
}
@PostMapping("/objective-complete")
public ResponseEntity<Object> authenticateObjective(@RequestBody ObjectiveRequest request) throws JsonProcessingException {
int response = objectiveService.completeObjective(request);
ObjectiveResponse responseObj = new ObjectiveResponse(response);
return new ResponseEntity<>(responseObj.toJSON(), HttpStatus.OK);
}
@GetMapping("/logout/{objectiveID}")
public ResponseEntity<Object> logoutPlayer(@PathVariable("objectiveID") int objectiveID) {
int response = objectiveService.getObjective(objectiveID);
return new ResponseEntity<>(response, HttpStatus.OK);
}
}
```
The `{objectiveID}` is a variable in the url for the Objective's ID. It is automatically passed in when Spring Boot receives the GET request.
\ No newline at end of file