Name: echidna
Owner: D3adspace Enterprises
Description: Simple and lightweight framework to create RESTful services.
Created: 2017-07-05 15:47:34.0
Updated: 2017-12-16 10:57:29.0
Pushed: 2017-07-05 16:12:30.0
Size: 33
Language: Java
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
Echidna is supposed to solve our problem of a missing simple and lightweight REST Framework.
`mvn clean install
`Maven dependencies
Echidna:
endency>
<groupId>de.d3adspace</groupId>
<artifactId>echidna-server</artifactId>
<version>1.0-SNAPSHOT</version>
pendency>
Server:
dnaConfig config = new EchidnaConfigBuilder()
.setServerPort(80)
.setServerHost("localhost")
.setResourceClasses(Collections.singletonList(new ExampleResource()))
.createEchidnaConfig();
dnaServer echidnaServer = EchidnaServerFactory.createEchidnaServer(config);
dnaServer.start();
Resource Example:
h("/rest/v1")
ic static class ExampleResource {
@GET
@Path("/user/del")
@Consumes("text/html")
@Produces("text/plain")
public HTTPResponse onUserDel(HTTPRequest request) {
return HTTPResponse.newBuilder()
.setStatus(HTTPStatus.OK)
.setBody(HTTPBody.fromString("Hey"))
.setHeaders(new HTTPHeaders())
.createHTTPResponse();
}
@GET
@Path("/user/del/{userId}")
@Consumes("text/html")
@Produces("text/plain")
public HTTPResponse onUserDelId(HTTPRequest request, String userId) {
return HTTPResponse.newBuilder()
.setStatus(HTTPStatus.OK)
.setBody(HTTPBody.fromString("Hey du " + userId))
.setHeaders(new HTTPHeaders())
.createHTTPResponse();
}
@POST
@Path("/user/add")
@Consumes("text/html")
@Produces("text/plain")
public HTTPResponse onUserDelIdPost(HTTPRequest request, @PostKey("test") String userId) {
System.out.println("Parameter: " + userId);
return HTTPResponse.newBuilder()
.setStatus(HTTPStatus.OK)
.setBody(HTTPBody.fromString("Hey du " + userId))
.setHeaders(new HTTPHeaders())
.createHTTPResponse();
}
Client Example:
dnaClient client = new EchidnaClient();
Request request = HTTPRequest
.newBuilder()
.setLocation("rest/v1/user/add")
.setMethod(HTTPMethod.POST)
.setVersion("HTTP/1.1")
.setHeaders(new HTTPHeaders())
.createHTTPRequest();
Body body = HTTPBody.newBodyBuilder("test", "IchBinDerBeste").build();
Response response = null;
{
response = client.request(new URL("http://localhost/rest/v1/user/add"), request, body);
tch (MalformedURLException e) {
e.printStackTrace();
em.out.println("Got Response: " + response);