Skip to content
Lightweight asynchronous HTTP/WS client/server
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples
src/lighttp Add asynchronous server responses Jan 7, 2019
views Add MimeTypes util and contentType property to Response Aug 8, 2018
.appveyor.yml
.editorconfig Initial commir Mar 18, 2018
.gitignore Start adding client Jan 6, 2019
.travis.yml
LICENSE Go back to libasync Jan 1, 2019
README.md Add MimeTypes util and contentType property to Response Aug 8, 2018
dub.sdl

README.md

lighttp Logo

DUB Package Build Status

Lighttp is a lightweight asynchronous HTTP and WebSocket server library for the D programming language with simple API.

import std.file;

import lighttp;

void main(string[] args) {

	Server server = new Server();
	server.host("0.0.0.0");
	server.host("::");
	server.router.add(new Router());
	server.router.add("GET", "welcome", new Resource("text/html", read("welcome.html")));
	server.run();

}

class Router {

	// GET /
	@Get("") getIndex(Response response) {
		response.body = "Welcome to lighttp!";
	}
	
	// GET /image/uhDUnsj => imageId = "uhDUnsj"
	@Get("image", "([a-zA-Z0-9]{7})") getImage(Response response, string imageId) {
		if(exists("images/" ~ imageId)) {
			response.contentType = MimeTypes.jpeg;
			response.body = read("images/" ~ imageId);
		} else {
			response.status = StatusCodes.notFound;
		}
	}

}
You can’t perform that action at this time.