Skip to content

Simple and lightweight framework to create RESTful services. Built on mantikor HTTP server.

License

Notifications You must be signed in to change notification settings

d3adspace/echidna

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Echidna

Echidna is supposed to solve our problem of a missing simple and lightweight REST Framework.

Installation / Usage

  • Install Maven
  • Clone this repo
  • Install: mvn clean install

Maven repositories

<repositories>
    <!-- Klauke Enterprises Releases -->
    <repository>
        <id>klauke-enterprises-maven-releases</id>
        <name>Klauke Enterprises Maven Releases</name>
        <url>https://repository.klauke-enterprises.com/repository/maven-releases/</url>
    </repository>
	
    <!-- Klauke Enterprises Snapshots -->
    <repository>
        <id>klauke-enterprises-maven-snapshots</id>
        <name>Klauke Enterprises Maven Snapshots</name>
        <url>https://repository.klauke-enterprises.com/repository/maven-snapshots/</url>
    </repository>
</repositories>

Maven dependencies

Echidna:

<dependency>
    <groupId>de.d3adspace.echidna</groupId>
    <artifactId>echidna-server</artifactId>
    <version>1.0-SNAPSHOT</version>
</dependency>

Example

Server:

EchidnaConfig config = new EchidnaConfigBuilder()
	.setServerPort(80)
	.setServerHost("localhost")
	.setResourceClasses(Collections.singletonList(new ExampleResource()))
	.createEchidnaConfig();
		
EchidnaServer echidnaServer = EchidnaServerFactory.createEchidnaServer(config);
		
echidnaServer.start();

Resource Example:

@Path("/rest/v1")
public 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:

EchidnaClient client = new EchidnaClient();
HTTPRequest request = HTTPRequest
	.newBuilder()
	.setLocation("rest/v1/user/add")
	.setMethod(HTTPMethod.POST)
	.setVersion("HTTP/1.1")
	.setHeaders(new HTTPHeaders())
	.createHTTPRequest();
		
HTTPBody body = HTTPBody.newBodyBuilder("test", "IchBinDerBeste").build();		
HTTPResponse response = null;

try {
	response = client.request(new URL("http://localhost/rest/v1/user/add"), request, body);
} catch (MalformedURLException e) {
	e.printStackTrace();
}
		
System.out.println("Got Response: " + response);

Releases

No releases published

Packages

No packages published

Languages