<commit_before># IronFunctions

## Quick Start

### Start the IronFunctions API

First let's start our IronFunctions API

```sh
docker run --rm --name functions --privileged -it -e "DB=bolt:///app/data/bolt.db" -v $PWD/data:/app/data -p 8080:8080 iron/functions
```

This command will quickly start IronFunctions using an embedded `Bolt` database running on `:8080`. 

### Create an Application

An application is essentially a grouping of functions, that put together, form an API. Here's how to create an app. 

```sh
curl -H "Content-Type: application/json" -X POST -d '{
    "app": { "name":"myapp" }
}' http://localhost:8080/v1/apps
```

Now that we have an app, we can map routes to functions. 

### Add a route to a Function

```sh
curl -H "Content-Type: application/json" -X POST -d '{
    "route": {
        "path":"/hello",
        "image":"iron/hello"
    }
}' http://localhost:8080/v1/apps/myapp/routes
```

### Calling your Function

Just hit the URL you got back from adding a route above:

```
curl http://localhost:8080/r/myapp/hello
```

### To pass in data to your function

Your function will get the body of the request as is, and the headers of the request will be passed in as env vars. Try this:

```sh
curl -H "Content-Type: application/json" -X POST -d '{
    "name":"Johnny"
}' http://localhost:8080/r/myapp/hello
```


##### Adding a route with URL params:

A route can pass params to a function by URL.

Example: This set the `PARAM_AUTHOR_ID` and `PARAM_NUM_PAGE` environment variables with value of params (`:author_id` and `:num_page`) passed in the URL.

```sh
$ curl -H "Content-Type: application/json" -X POST -d '{
     "route": {
         "path":"/comments/:author_id/:num_page",
         "image":"IMAGE_NAME"
     }
}' http://localhost:8080/v1/apps/myapp/routes
```


See the [Blog Example](https://github.com/iron-io/functions/blob/master/examples/blog/README.md#creating-our-blog-application-in-your-ironfunctions).


## Adding Asynchronous Data Processing Support

Data processing is for functions that run in the background. This type of functionality is good for functions that are CPU heavy or take more than a few seconds to complete. 
Architecturally, the main difference between synchronous you tried above and asynchronous is that requests
to asynchronous functions are put in a queue and executed on separate `runner` machines so that they do not interfere with the fast synchronous responses required by an API. Also, since 
it uses a queue, you can queue up millions of jobs without worrying about capacity as requests will just be queued up and run at some point in the future.  

TODO: Add link to differences here in README.io docs here. 

### Start Runner(s)

Start a runner:

```sh
docker run --rm -it --link functions --privileged -e "API_URL=http://functions:8080" iron/functions-runner
```

You can start as many runners as you want. The more the merrier.

For runner configuration, see the [Runner README](runner/README.md).<commit_msg>fix irregular header and texts<commit_after># IronFunctions

## Quick Start

### Start the IronFunctions API

First let's start our IronFunctions API

```sh
docker run --rm --name functions --privileged -it -e "DB=bolt:///app/data/bolt.db" -v $PWD/data:/app/data -p 8080:8080 iron/functions
```

This command will quickly start IronFunctions using an embedded `Bolt` database running on `:8080`. 

### Create an Application

An application is essentially a grouping of functions, that put together, form an API. Here's how to create an app. 

```sh
curl -H "Content-Type: application/json" -X POST -d '{
    "app": { "name":"myapp" }
}' http://localhost:8080/v1/apps
```

Now that we have an app, we can map routes to functions. 

### Add a route to a Function

```sh
curl -H "Content-Type: application/json" -X POST -d '{
    "route": {
        "path":"/hello",
        "image":"iron/hello"
    }
}' http://localhost:8080/v1/apps/myapp/routes
```

### Calling your Function

Just hit the URL you got back from adding a route above:

```
curl http://localhost:8080/r/myapp/hello
```

### To pass in data to your function

Your function will get the body of the request as is, and the headers of the request will be passed in as env vars. Try this:

```sh
curl -H "Content-Type: application/json" -X POST -d '{
    "name":"Johnny"
}' http://localhost:8080/r/myapp/hello
```


**Adding a route with URL params**

You can create a route with dynamic URL parameters that will be available inside your function by prefixing path segments with a `:`, for example:

```sh
$ curl -H "Content-Type: application/json" -X POST -d '{
     "route": {
         "path":"/comments/:author_id/:num_page",
         "image":"IMAGE_NAME"
     }
}' http://localhost:8080/v1/apps/myapp/routes
```

`:author_id` and `:num_page` in the path will be passed into your function as `PARAM_AUTHOR_ID` and `PARAM_NUM_PAGE`.


See the [Blog Example](https://github.com/iron-io/functions/blob/master/examples/blog/README.md#creating-our-blog-application-in-your-ironfunctions).


## Adding Asynchronous Data Processing Support

Data processing is for functions that run in the background. This type of functionality is good for functions that are CPU heavy or take more than a few seconds to complete. 
Architecturally, the main difference between synchronous you tried above and asynchronous is that requests
to asynchronous functions are put in a queue and executed on separate `runner` machines so that they do not interfere with the fast synchronous responses required by an API. Also, since 
it uses a queue, you can queue up millions of jobs without worrying about capacity as requests will just be queued up and run at some point in the future.  

TODO: Add link to differences here in README.io docs here. 

### Start Runner(s)

Start a runner:

```sh
docker run --rm -it --link functions --privileged -e "API_URL=http://functions:8080" iron/functions-runner
```

You can start as many runners as you want. The more the merrier.

For runner configuration, see the [Runner README](runner/README.md).
{'fraction_non_alphanumeric': 0.1118800461361015, 'fraction_numerical': 0.012852199703410776, 'mean_word_length': 3.779527559055118, 'pattern_counts': {'":': 18, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '388692', 'n_tokens_mistral': 1898, 'n_tokens_neox': 1741, 'n_words': 765}