Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

d3adspace/echidna

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);

About

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

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

Languages

AltStyle によって変換されたページ (->オリジナル) /