Documentation - Studio182/StudioHTTPd GitHub Wiki

Please note: These are very early docs on a very beta project. Please be patient. Look on the next page for information on how to contact the app developers.

Set up

For setting the server up, do this:

  1. On your AppDelegate header, #import "StudioHTTPd.h" file and add the delegate StudioHTTPdDelegate.

  2. On the implementation #import "StudioHTTPd.h" too, and in the place where you'd like to launch the server, write this:

     StudioHTTPd *httpd = [[StudioHTTPd alloc] initWithPort:40182];
     [httpd setDelegate:self];
     [httpd startServer];
    
  3. Add the delegate call:

     -(void)writeToLog:(NSString*)data {
      	NSLog(@"%@", data);
      	//The server log
     }
    
  4. And you're set with the basic server! Was easy, huh?

Templating system

Setting a Variable

The StudioHTTPd Templating system is inspired by the templating systems similar to Ruby and Rails.

This means that there are two parts to a webpage. A processing script and a template.

To create a processing script you need to go to the WebClass.m file.

To create a new action. Make an entry like this.

+(id)helloworld:(NSDictionary*)args {
//Initilize Variable Array

NSMutableDictionary *variables = [[NSMutableDictionary alloc] initWithDictionary:args];

// Begin Coding


[variables setObject:@"Studio 182" forKey:@"name"];


// End Coding

// Return Templatized


//Please note that we used helloworld as the templatize variable. This means we are using a template with the name "helloworld"
return [templatizer templatize:@"helloworld" variables:variables];
}

This will create an action named helloworld.


Lets take a look at each line and what it does.

NSMutableDictionary *variables = [[NSMutableDictionary alloc] initWithDictionary:args];

This sets up a NSMutableDictionary. The point of this line is to make a variable that you can add data to.

[variables setObject:@"Studio 182" forKey:@"name"];

This sets a variable to be used later in the template.

return [templatizer templatize:@"helloworld" variables:variables];

This returns the response information back to the server. If you wanted to return data instead of a template you could just have

return @"returned data";

Accessing GET variables from code

To access GET variable from code it's as simple as typing

 NSString *getVAR = [args objectForKey:@"GET_VARIABLE_NAME"];

The templating system

The templating system is very easy to use in Studio 182. All you have to do is create a file in templates directory.

Above we called for a template named helloworld. You are going to want to create a file named "helloworld.html"

Inside put

Simple GET Variable: ##GET['namevar']##
  
Simple Code Variable: ##@['name']##

Part 2 >

⚠️ **GitHub.com Fallback** ⚠️