Skip to content


Subversion checkout URL

You can clone with
Download ZIP
A minimal, high-performance Objective-C library to write self-sufficient web applications. Built on top of Mongoose.
Objective-C Matlab
Latest commit 19b1255 @fjolnir added MONGOOSE_DEBUG


HTTPKit is a lightweight framework for building webservers in Objective-C or Tranquil.

Basic usage

#import <HTTPKit.h>

int main(int argc, const char * argv[])
    @autoreleasepool {
        HTTP *http = [HTTP new];
        // Simple "Hello you!" pong
        [http handleGET:@"/hello/*"
                   with:^(HTTPConnection *connection, NSString *name) {
            return [NSString stringWithFormat:@"Hello %@!", name];

        // Simplified login example
        [http handleGET:@"/login"
                   with:^(HTTPConnection *connection) {
                       return @"<form method=\"post\" action=\"/login\">"
                              @"<label for=\"username\">Name:</label>"
                              @"<input name=\"username\" type=\"text\">"
                              @"<label for=\"password\">Password:</label>"
                              @"<input name=\"password\" type=\"password\">"
                              @"<input type=\"submit\" value=\"Sign in\">"
        [http handlePOST:@"/login" with:^(HTTPConnection *connection) {
            NSLog(@"logging in user: %@ with password: %@",
                  [connection requestBodyVar:@"username"],
                  [connection requestBodyVar:@"password"]);
            return @"Welcome! I trust you so I didn't even check your password.";
        [http listenOnPort:8081 onError:^(id reason) {
            fprintf(stderr, "Error starting server: %s", [reason UTF8String]);
        [[NSRunLoop mainRunLoop] runUntilDate:[NSDate distantFuture]];
    return 0;

Or written in tranquil as:

import "HTTPKit"
import "html"
t = Tag
HTTP new handleGET: "/hello/*" with: `conn, name| "Hello «name»!"`;
         handleGET: "/login" with: { conn |
             t html: "Log in" :[
                 t :#form :[
                     t :#label :"Name:" :{ #for  => #username },
                     t :#input :nil     :{ #name => #username, #type => #text },
                     t :#label :"Password:" :{ #for  => #password },
                     t :#input :nil         :{ #name => #password, #type => #password },
                     t :#input :nil :{ #value => "Sign in", #type => #submit  }
                 ] :{ #method => #post }
        handlePOST: "/login" with: { conn |
             "Logging in user: «conn requestBodyVar: #username» with password: «conn requestBodyVar: #password»" print
             ^"Welcome! I trust you so I didn't even check your password."
        listenOnPort: 8080 onError: { reason | "Error starting server: «reason»" print. ^^1 }

NSRunLoop mainRunLoop runUntilDate: NSDate distantFuture
Something went wrong with that request. Please try again.