-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [BLZT-10,11] added tests and started java doc * [BLZT-10,11] added test for MissingBringServletImplException when RestController does not implement BringServlet interface * [BLZT-10,11] added java docs except DispatcherServlet and tests * [BLZT-10,11] fixed lower case package name * [BLZT-10,11] fixed build error * [BLZT-10,11] fixed build error * [BLZT-10,11] refactoring and java docs for DispatcherServlet * [BLZT-10,11] markdown for web package * [BLZT-10,11] new markdowns for web package * [BLZT-83] ResponseEntity implementation, java doc, markdown * [BLZT-83] small improvements * [BLZT-83] BringServlet.md * [BLZT-83] small improvements
- Loading branch information
1 parent
d48d7e4
commit eec6ead
Showing
42 changed files
with
498 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# BringServlet Interface Documentation | ||
|
||
The `BringServlet` interface is a marker interface used to identify classes that need to be implemented for use as REST controllers within the Bring framework. Classes implementing this interface play a significant role in the configuration and setup of the REST controller context. | ||
|
||
## Overview | ||
|
||
The primary purpose of the `BringServlet` interface is to act as a marker, signaling to the system that a particular class should be recognized as a servlet within the Bring framework. It does not mandate the addition of any specific methods, serving solely as an indicator for classes that should be included in the REST controller context setup. | ||
|
||
## Usage | ||
|
||
To make use of the `BringServlet` interface, a class needs to implement it: | ||
|
||
```java | ||
@RestController | ||
public class MyRestController implements BringServlet { | ||
// REST controller logic and methods | ||
} | ||
``` | ||
|
||
### See Also | ||
[RestController](https://github.com/YevgenDemoTestOrganization/bring/blob/d1df5bd13e15033caad3f012bc3ef5c3be780c1f/features/web/servlet/annotation/RestController.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# ResponseEntity Class Documentation | ||
|
||
The `ResponseEntity` class represents an HTTP response entity in the context of a Spring application. It encapsulates the response body, headers, and HTTP status, providing flexibility and control over the structure of the API response. | ||
|
||
## Overview | ||
|
||
The primary purpose of `ResponseEntity` is to allow developers to customize the HTTP response sent from a controller method. It becomes particularly useful when working in conjunction with the `@ResponseStatus` annotation. | ||
|
||
**Note:** When both `ResponseEntity` and `@ResponseStatus` are used in a controller method, the HTTP status from `ResponseEntity` takes precedence over the one specified by `@ResponseStatus`. | ||
|
||
## Generic Type Parameter | ||
|
||
The class is generic, allowing the specification of the type of the response body using the type parameter `<T>`. | ||
|
||
```java | ||
public class ResponseEntity<T> { | ||
// class implementation | ||
} | ||
``` | ||
|
||
### Constructors | ||
|
||
1. Full Constructor | ||
``` | ||
public ResponseEntity(T body, HttpHeaders headers, HttpStatus httpStatus) | ||
``` | ||
Constructs a new ResponseEntity with the given response body, headers, and HTTP status. | ||
|
||
2. Constructor with Body and Status | ||
``` | ||
public ResponseEntity(T body, HttpStatus httpStatus) | ||
``` | ||
Constructs a new ResponseEntity with the given response body and HTTP status. Headers are set to null. | ||
|
||
3. Constructor with Headers and Status | ||
``` | ||
public ResponseEntity(HttpHeaders headers, HttpStatus httpStatus) | ||
``` | ||
Constructs a new ResponseEntity with the given headers and HTTP status. The response body is set to null. | ||
|
||
### Methods | ||
|
||
#### `getHeaders()` | ||
Gets the headers included in the response. | ||
|
||
#### `getBody()` | ||
Gets the body of the response. | ||
|
||
#### `getHttpStatus()` | ||
Gets the HTTP status of the response. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
# Building REST API with Bring: A Quick Guide | ||
|
||
## Introduction | ||
|
||
When building a RESTful API using the Bring framework, the annotations like [`@RestController`](https://github.com/YevgenDemoTestOrganization/bring/blob/d1df5bd13e15033caad3f012bc3ef5c3be780c1f/features/web/servlet/annotation/RestController.md), | ||
[`@RequestMapping`](https://github.com/YevgenDemoTestOrganization/bring/blob/d1df5bd13e15033caad3f012bc3ef5c3be780c1f/features/web/servlet/annotation/PostMapping.md), | ||
[`@GetMapping`](https://github.com/YevgenDemoTestOrganization/bring/blob/d1df5bd13e15033caad3f012bc3ef5c3be780c1f/features/web/servlet/annotation/GetMapping.md), | ||
[`@PathVariable`](https://github.com/YevgenDemoTestOrganization/bring/blob/d1df5bd13e15033caad3f012bc3ef5c3be780c1f/features/web/servlet/annotation/PathVariable.md), | ||
[`@RequstBody`](https://github.com/YevgenDemoTestOrganization/bring/blob/d1df5bd13e15033caad3f012bc3ef5c3be780c1f/features/web/servlet/annotation/RequestBody.md) and others can be used. | ||
These annotations simplify the development process and ensure a standardized approach to creating web services. | ||
[`ResponseEntity`](https://github.com/YevgenDemoTestOrganization/bring/blob/d1df5bd13e15033caad3f012bc3ef5c3be780c1f/features/web/servlet/ResponseEntity.md) allows you to customize the HTTP response, including status codes, headers, and the response body. | ||
This guide will walk you through the essential steps to set up a REST controller. | ||
|
||
**1. Create a REST Controller** | ||
|
||
To get started, create a class and annotate it with | ||
[`@RestController`](https://github.com/YevgenDemoTestOrganization/bring/blob/d1df5bd13e15033caad3f012bc3ef5c3be780c1f/features/web/servlet/annotation/RestController.md). | ||
This annotation indicates that the class will handle HTTP requests and produce HTTP responses for a RESTful API. | ||
The class should implement marker interface | ||
[`BringServlet`](https://github.com/YevgenDemoTestOrganization/bring/blob/d1df5bd13e15033caad3f012bc3ef5c3be780c1f/features/web/servlet/BringServlet.md) to be recognized as controller by the framework and setup of the REST controller context. | ||
The [`@RequestMapping`](https://github.com/YevgenDemoTestOrganization/bring/blob/d1df5bd13e15033caad3f012bc3ef5c3be780c1f/features/web/servlet/annotation/RequestMapping.md) annotation can be utilized to define the base path for all endpoints in the controller (`/api`). | ||
|
||
**Example:** | ||
```java | ||
@RestController | ||
@RequestMapping(path = "/api") | ||
public class MyRestController implements BringServlet { | ||
// REST controller logic and methods | ||
} | ||
``` | ||
|
||
**2. Define Endpoints with @GetMapping** | ||
|
||
Use the @GetMapping annotation to define methods that handle HTTP GET requests. These methods will serve as endpoints for retrieving information. | ||
When you need to extract values from the URI use the `@PathVariable` or `@RequestParam` annotation. | ||
|
||
**Example:** | ||
```java | ||
@RestController | ||
@RequestMapping(path = "/api") | ||
public class MyRestController implements BringServlet { | ||
|
||
@GetMapping(path = "/resource/{id}") | ||
public ResponseEntity<Resource> getResource(@PathVariable Long id) { | ||
// Your implementation logic here | ||
} | ||
} | ||
``` | ||
**Example:** | ||
```java | ||
@RestController | ||
@RequestMapping(path = "/api") | ||
public class MyRestController implements BringServlet { | ||
|
||
@GetMapping(path = "/resource") | ||
public ResponseEntity<Resource> getResource(@RequestParam Long id, @RequestParam String name) { | ||
// Your implementation logic here | ||
} | ||
} | ||
``` | ||
|
||
**3. Define Endpoints with @PutMapping** | ||
|
||
Use the `@PutMapping` annotation to define methods that handle HTTP PUT requests. These methods will serve as endpoints for updating existing resources. | ||
|
||
**Example:** | ||
```java | ||
@RestController | ||
@RequestMapping(path = "/api") | ||
public class MyRestController implements BringServlet { | ||
|
||
@PutMapping(path = "/resource/{id}") | ||
public ResponseEntity<String> updateResource(@PathVariable Long id, | ||
@RequestBody UserDto dto) { | ||
// Your implementation logic here | ||
} | ||
} | ||
``` | ||
Here, the updateResource method handles `PUT` requests to `/api/resource/{id}`. | ||
The `@PathVariable` annotation extracts the id from the URI and `@RequestBody` is used to capture the data sent in the request body. | ||
|
||
**4. Define Endpoints with @RequestHeader** | ||
|
||
Utilize the @RequestHeader annotation to extract values from HTTP headers in your endpoint methods. | ||
|
||
**Example:** | ||
```java | ||
@RestController | ||
@RequestMapping(path = "/api") | ||
public class MyRestController implements BringServlet { | ||
|
||
@PostMapping(path = "/resource") | ||
public ResponseEntity<String> resourceHeaders(@RequestHeader("Authorization") String authToken) { | ||
// Your implementation logic here | ||
} | ||
} | ||
``` | ||
**5. Use ResponseEntity for Flexible Responses** | ||
|
||
`ResponseEntity` allows to customize the HTTP response, including status codes, headers and the response body. | ||
|
||
**Example:** | ||
|
||
```java | ||
import java.util.ResourceBundle; | ||
|
||
@RestController | ||
@RequestMapping(path = "/api") | ||
public class MyRestController implements BringServlet { | ||
|
||
@PostMapping(path = "/resource") | ||
public ResponseEntity<Resource> saveResource(@RequestBody ResourceDto dto) { | ||
// Save resource to DB | ||
Resource resource = saveToDB(dto); | ||
|
||
// Set custom headers | ||
HttpHeaders headers = new HttpHeaders(); | ||
headers.set("Custom", "Value"); | ||
|
||
// return instance of ResponseEntity | ||
return new ResponseEntity<>(resource, headers, HttpStatus.OK); | ||
} | ||
} | ||
``` | ||
|
||
**6. Define Endpoints with @ResponseStatus** | ||
|
||
Utilize the @ResponseStatus annotation to define the desired HTTP response status code for specific methods. | ||
|
||
**Example:** | ||
```java | ||
@RestController | ||
@RequestMapping(path = "/api") | ||
public class MyRestController implements BringServlet { | ||
|
||
@PutMapping(path = "/resource/{id}") | ||
@ResponseStatus(value = HttpStatus.NO_CONTENT) | ||
public ResponseEntity<String> updateResource(@PathVariable Long id, | ||
@RequestBody UserDto dto) { | ||
// Your implementation logic here | ||
} | ||
} | ||
``` | ||
**NOTE:** When both `ResponseEntity` and `@ResponseStatus` are used in a controller method, | ||
the HTTP status from `ResponseEntity` takes precedence over the one specified by `@ResponseStatus`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.