Skip to content

josip/meh

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MEH

An __m__inimalist, __e__mbeddable, self-__h__osted and self-aware* HTTP server for C#

Usage

Writing a MEH server is incredibly easy:

	using MEH;

	namespace SuperTrouperApp {
		class Stage : HttpServer {
			// ...
		}
	}

New request handlers (ie. routes in "richer" libraries) are added through GET and POST methods:

	public Stage(int port) : base(port) {
		POST(@"/feeling/(\w)$", (m, p) => {
			string number = p.inputStream.ReadToEnd();
			p.Respond(String.Format("Feeling like a {0}, {1}", m[1].Value, number));
		});
		GET(@"/", (m, p) => p.Respond("BEAMS ARE GONNA BLIND ME"));
	}

The m argument is a System.Text.RegularExpressions.GroupCollection, while p represents an internal class, HttpProcessor. The only thing about HttpProcessor that you need to know is its Respond method:

	public Stage(int port) : base(port) {
		GET(@"/find/trouper/w/lights", (m, p) => p.Respond("Shining like the sun?"));
		GET(@"/find/trouper", (m, p) => p.Respond(HttpStatusCodes.NotFound));
		GET(@"/find/tea", (m, p) => p.Respond(HttpStatusCodes.ImATeapot, "Are you a teapot?"));
		GET(@"/find/waldo", (m, p) => {
			Dictionary<string, string> headers = new Dictionary<string, string>();
			headers.add("X-Quadrant", "Left");
			headers.add("X-Clues", "None");
			p.respond(HttpStatusCodes.SeeOther, headers, "Hmmm...");
		});
	}

You're now 200 to start using the "library".

Oh yes, MEH can serve static files as well. Take a look at the ServeFiles method, I don't feel like writing about it right now. meh.

License

MEH is based on the works of David Jeske, and as the original work, meh is published to public domain. Have fun!

Footnotes

* – self-aware of its limitations

About

An minimalist, embeddable, self-hosted and self-aware HTTP server for C#

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages