github.com/iron-io/functions@v0.0.0-20180820112432-d59d7d1c40b2/docs/operating/routes.md (about) 1 # IronFunctions Routes 2 3 Routes have a many-to-one mapping to an [app](apps.md). 4 5 A good practice to get the best performance on your IronFunctions API is define 6 the required memory for each function. 7 8 ## Route level configuration 9 10 When creating a route, you can configure it to tweak its behavior, the possible 11 choices are: `memory`, `type` and `config`. 12 13 `memory` is number of usable MiB for this function. If during the execution it 14 exceeds this maximum threshold, it will halt and return an error in the logs. It 15 expects to be an integer. Default: `128`. 16 17 `type` is the type of the function. Either `sync`, in which the client waits 18 until the request is successfully completed, or `async`, in which the clients 19 dispatches a new request, gets a task ID back and closes the HTTP connection. 20 Default: `sync`. 21 22 `config` is a map of values passed to the route runtime in the form of 23 environment variables. 24 25 Note: Route level configuration overrides app level configuration. 26 27 TODO: link to swagger doc on swaggerhub after it's updated. 28 29 ## Understanding IronFunctions memory management 30 31 When IronFunctions starts it registers the total available memory in your system 32 in order to know during its runtime if the system has the required amount of 33 free memory to run each function. Every function starts the runner reduces the 34 amount of memory used by that function from the available memory register. When 35 the function finishes the runner returns the used memory to the available memory 36 register. 37 38 ### Creating function 39 40 ``` 41 curl -H "Content-Type: application/json" -X POST -d '{ 42 "route": { 43 "path":"<route name>", 44 "image":"<route image>", 45 "memory": <memory mb number>, 46 "type": "<route type>", 47 "config": {"<unique key>": <value>} 48 } 49 }' http://localhost:8080/v1/apps/<app name>/routes 50 ``` 51 52 Eg. Creating `/myapp/hello` with required memory as `100mb`, type `sync` and 53 some container configuration values. 54 55 ``` 56 curl -H "Content-Type: application/json" -X POST -d '{ 57 "route": { 58 "path":"/hello", 59 "image":"iron/hello", 60 "memory": 100, 61 "type": "sync", 62 "config": {"APPLOG": "stderr"} 63 } 64 }' http://localhost:8080/v1/apps/myapp/routes 65 ``` 66 67 ### Updating function 68 69 ``` 70 curl -H "Content-Type: application/json" -X POST -d '{ 71 "route": { 72 "memory": <memory mb number>, 73 "type": "<route type>", 74 "config": {"<unique key>": <value>} 75 } 76 }' http://localhost:8080/v1/apps/<app name>/routes/<route name> 77 ``` 78 79 Eg. Updating `/myapp/hello` required memory as `100mb`, type `async` and changed 80 container configuration values. 81 82 ``` 83 curl -H "Content-Type: application/json" -X POST -d '{ 84 "route": { 85 "memory": 100, 86 "type": "async", 87 "config": {"APPLOG": "stdout"} 88 } 89 }' http://localhost:8080/v1/apps/myapp/routes/hello 90 ```