From bb0f62416eab9f9b38dfc09b9294ba553131ef08 Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Latour Date: Tue, 15 Apr 2014 01:24:31 -0300 Subject: [PATCH] Update README.md --- README.md | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 2e95700..34a3607 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Overview [![Build Status](https://travis-ci.org/swisspol/GCDWebServer.svg?branch=master)](https://travis-ci.org/swisspol/GCDWebServer) -GCDWebServer is a modern and lightweight GCD based HTTP 1.1 server designed to be embedded in Mac & iOS apps. It was written from scratch with the following goals in mind: +GCDWebServer is a modern and lightweight GCD based HTTP 1.1 server designed to be embedded in OS X & iOS apps. It was written from scratch with the following goals in mind: * Easy to use and understand architecture with only 4 core classes: server, connection, request and response (see "Understanding GCDWebServer's Architecture" below) * Well designed API for easy integration and customization * Entirely built with an event-driven design using [Grand Central Dispatch](http://en.wikipedia.org/wiki/Grand_Central_Dispatch) for maximal performance and concurrency @@ -55,8 +55,9 @@ pod "GCDWebServer/WebDAV", "~> 2.0" Hello World =========== -This code snippet shows how to implement a custom HTTP server that runs on port 8080 and returns a "Hello World" HTML page to any request — since GCDWebServer uses GCD blocks to handle requests, no subclassing or delegates are needed, which results in very clean code: +These codes snippets show how to implement a custom HTTP server that runs on port 8080 and returns a "Hello World" HTML page to any request. Since GCDWebServer uses GCD blocks to handle requests, no subclassing or delegates are needed, which results in very clean code. +**OS X version (command line tool):** ```objectivec #import "GCDWebServer.h" @@ -75,7 +76,7 @@ int main(int argc, const char* argv[]) { }]; - // Use convenience method that runs server on port 8080 until SIGINT received (Ctrl-C in Terminal) + // Use convenience method that runs server on port 8080 until SIGINT received (i.e. Ctrl-C in Terminal) [webServer runWithPort:8080]; // Destroy server @@ -86,6 +87,33 @@ int main(int argc, const char* argv[]) { } ``` +**iOS Version:** +```objectivec +#import "GCDWebServer.h" + +static GCDWebServer* _webServer = nil; // This should be an ivar of your application delegate class instead + +- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions { + + // Create server + _webServer = [[GCDWebServer alloc] init]; + + // Add a handler to respond to GET requests on any URL + [_webServer addDefaultHandlerForMethod:@"GET" + requestClass:[GCDWebServerRequest class] + processBlock:^GCDWebServerResponse *(GCDWebServerRequest* request) { + + return [GCDWebServerDataResponse responseWithHTML:@"

Hello World

"]; + + }]; + + // Start server on port 8080 + [_webServer startWithPort:8080 bonjourName:nil]; + + return YES; +} +``` + Web Based Uploads in iOS Apps =============================