• Stars
    star
    210
  • Rank 187,585 (Top 4 %)
  • Language
    Objective-C
  • Created almost 12 years ago
  • Updated almost 9 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A minimal, high-performance Objective-C library to write self-sufficient web applications. Built on top of Mongoose.

HTTPKit

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

Build steps

  • git clone --recursive https://github.com/fjolnir/HTTPKit.git
  • Edit the SDKVERSION in dependencies/iphone-openssl/build-libssl.sh to match your current Xcode's SDK version.
  • execute build-libssl.sh
  • Open Xcode project and hit build.

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\">"
                              @"</form>";
                   }];
        [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]);
            exit(1);
        }];
        [[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

More Repositories

1

xnomad

A tiling window manager for OS X, written in tranquil.
C
483
star
2

DatabaseKit

An Objective-C database abstraction framework.
Objective-C
383
star
3

Tranquil

A language built on top of the Objective-C runtime, and ABI compatible with Objective-C.
Objective-C++
323
star
4

TLC

The Tiny Lua Cocoa Bridge
Lua
136
star
5

CoreFoundation-Lite-Linux

CFLite fixed to build correctly on linux (Tested on debian with clang 3.0)
C
38
star
6

Menufela

A little SIMBL hack that enables you to toggle the menubar on/off.
Objective-C
34
star
7

Tranquil-Live

A Lua LiveCoding environment for Mac
Objective-C
16
star
8

CodeRunner-templates

My CodeRunner templates (See readme for list)
Shell
15
star
9

GLMath

Simple math toolkit for use in computer graphics
C
14
star
10

Blackshades

Blackshades fixed to make it build on osx (Blackshades was created by Wolfire games - http://www.wolfire.com)
C++
13
star
11

yaccviso

Yacc grammar visualizer –– This repo is no longer maintained, please use Kaplan's official repo instead.
C
10
star
12

sekwenser

A step sequencer for use with the Korg PadKONTROL
Objective-C
10
star
13

Dynamo

A little OpenGL powered 2d engine written in C (That is very much in progress)
C
8
star
14

Beets

A little iPhone utility that listens to music through the mic and displays its BPM
Objective-C
7
star
15

FABatching

A single header library for adding allocation batching&pooling to Objective-C classes.
C
3
star
16

ShaderToy

A little app that runs fragment shaders in a ShaderToy.com like environment locally
Objective-C
3
star
17

FConvenience

Nice to have macros, for writing less cluttered code
Objective-C
3
star
18

Foundation-Lite

A subset of Foundation for Linux [Not maintained]
Objective-C
3
star
19

CoreFoundation-Lite-OS-X

CoreFoundation fixed to build on retail OS X (See readme for build instructions)
C
2
star
20

Dynamo-Android-Sample

A simple Android sample for Dynamo
C
2
star
21

objc-autoinit

Automatic init methods for Objective-C
C
2
star
22

Dynamo-iOS-Sample

A simple iOS sample for Dynamo
Objective-C
1
star
23

qdnes

Quick&Dirty NES, a toy project I'm using to learn how to write emulators (Not even close to working, and may never)
C++
1
star
24

marklit

A little tool for writing literate C code using markdown
Ruby
1
star
25

FLazyObjects

Classes for lazily allocating objects.
Objective-C
1
star
26

Scroll-availability-indicators

A little hack that adds a shadow on the edges of scroll views if there is content out of view (in Lion)
Objective-C
1
star