https://github.com/damianwajser/spring-rest-commons-options
This project contains the general-purpose documentation to spring rest api http options
https://github.com/damianwajser/spring-rest-commons-options
http options options-parsing rest rest-api spring spring-boot
Last synced: 6 months ago
JSON representation
This project contains the general-purpose documentation to spring rest api http options
- Host: GitHub
- URL: https://github.com/damianwajser/spring-rest-commons-options
- Owner: damianwajser
- License: apache-2.0
- Created: 2017-11-02T03:27:38.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-12-11T23:08:24.000Z (over 8 years ago)
- Last Synced: 2025-07-23T04:37:40.407Z (12 months ago)
- Topics: http, options, options-parsing, rest, rest-api, spring, spring-boot
- Language: Java
- Homepage:
- Size: 657 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# spring-rest-commons-options

[](https://travis-ci.org/damianwajser/spring-rest-commons-options) [](https://bestpractices.coreinfrastructure.org/projects/1400) [](https://maven-badges.herokuapp.com/maven-central/com.github.damianwajser/spring-rest-commons-options) [](https://codeclimate.com/github/damianwajser/spring-rest-commons-options/maintainability) [](https://sonarcloud.io/dashboard?id=com.github.damianwajser%3Aspring-rest-commons-options)
[](https://sonarcloud.io/dashboard?id=com.github.damianwajser%3Aspring-rest-commons-options)
## Overview
This project contains the general-purpose documentation to spring rest api http options.
Project is licensed under [Apache License 2.0](http://www.apache.org/licenses/LICENSE-2.0).
-----
## Roadmap
Consult the proyect for details on the current [spring-rest-commons-options roadmap](https://github.com/damianwajser/spring-rest-commons-options/projects/1).
## Get it!
### Install
#### Maven
Functionality of this package is contained in Java package `com.github.damianwajser`, and can be used using following Maven dependency:
```xml
...
{lastversion}
...
...
com.github.damianwajser
spring-rest-commons-options
${options.spring.docs}
...
```
#### Gradle
```xml
compile 'com.github.damianwajser:spring-rest-commons-options:0.0.17'
```
## Usage
Create a spring-boot application.
```java
//declare the package to create de options controllers
@ComponentScan({"com.github.damianwajser","{YOUR-PINCIPAL-PACKAGE}"})
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
```
### Example
Create the model, if you required, add the validation with the hibernate-validators or java-validators:
```java
public class Example {
@NotEmpty(message = "The field description is required")
private String description;
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}
```
Create a Controller:
```java
@RestController
@RequestMapping("/example")
public class ExapmleResource {
@GetMapping("/{id}")
public Example getById(@PathVariable("id") Integer id) {
Example example = new Example();
example.setDescription("description");
return example;
}
@PostMapping("/")
public Example post(@Valid Example example) {
return example;
}
}
```
Full example: https://github.com/damianwajser/spring-rest-commons-options-example
### Test It!!
The firts enpooint created:
```curl
curl -X GET http://localhost:8080/endpoints
```
The response:
```js
["/example","/endpoints"]
```
#### Check options
```curl
curl -X OPTIONS http://localhost:8080/example
```
Response:
```js
{
"resources": {
"/example": {
"endpoints": [
{
"endpoint": "GET - /example/{id}",
"httpMethod": "GET",
"relativeUrl": "/{id}",
"queryString": {
"params": []
},
"pathVariable": {
"params": [
{
"required": true,
"name": "id",
"type": "Integer"
}
]
},
"bodyRequest": {
"fields": [],
"jsonSchema": null
},
"bodyResponse": {
"fields": [
{
"name": "description",
"type": "String",
"auditable": false
}
],
"jsonSchema": {
"type": "object",
"id": "urn:jsonschema:com:test:damianwajser:model:Example",
"properties": {
"description": {
"type": "string"
}
}
}
},
"headers": [],
"url": "/example/{id}"
},
{
"endpoint": "GET - /example/{id}",
"httpMethod": "GET",
"relativeUrl": "/{id}",
"queryString": {
"params": []
},
"pathVariable": {
"params": [
{
"required": true,
"name": "id",
"type": "Integer"
}
]
},
"bodyRequest": {
"fields": [],
"jsonSchema": null
},
"bodyResponse": {
"fields": [
{
"name": "description",
"type": "String",
"auditable": false
}
],
"jsonSchema": {
"type": "object",
"id": "urn:jsonschema:com:test:damianwajser:model:Example",
"properties": {
"description": {
"type": "string"
}
}
}
},
"headers": [],
"url": "/example/{id}"
},
{
"endpoint": "POST - /example",
"httpMethod": "POST",
"relativeUrl": "",
"queryString": {
"params": []
},
"pathVariable": {
"params": []
},
"bodyRequest": {
"fields": [
{
"name": "description",
"type": "String",
"auditable": false,
"validation": [
{
"name": "NotEmpty",
"message": "The field description is required"
}
]
}
],
"jsonSchema": {
"type": "object",
"id": "urn:jsonschema:com:test:damianwajser:model:Example",
"properties": {
"description": {
"type": "string"
}
}
}
},
"bodyResponse": {
"fields": [
{
"name": "description",
"type": "String",
"auditable": false
}
],
"jsonSchema": {
"type": "object",
"id": "urn:jsonschema:com:test:damianwajser:model:Example",
"properties": {
"description": {
"type": "string"
}
}
}
},
"headers": [],
"url": "/example"
},
{
"endpoint": "POST - /example",
"httpMethod": "POST",
"relativeUrl": "",
"queryString": {
"params": []
},
"pathVariable": {
"params": []
},
"bodyRequest": {
"fields": [
{
"name": "description",
"type": "String",
"auditable": false,
"validation": [
{
"name": "NotEmpty",
"message": "The field description is required"
}
]
}
],
"jsonSchema": {
"type": "object",
"id": "urn:jsonschema:com:test:damianwajser:model:Example",
"properties": {
"description": {
"type": "string"
}
}
}
},
"bodyResponse": {
"fields": [
{
"name": "description",
"type": "String",
"auditable": false
}
],
"jsonSchema": {
"type": "object",
"id": "urn:jsonschema:com:test:damianwajser:model:Example",
"properties": {
"description": {
"type": "string"
}
}
}
},
"headers": [],
"url": "/example"
}
]
}
},
"httpCodes": {}
}
```
## License
The Spring Framework is released under version 2.0 of the
[Apache License](http://www.apache.org/licenses/LICENSE-2.0).