mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
108 lines
2.3 KiB
Markdown
108 lines
2.3 KiB
Markdown
# IronFunctions
|
|
|
|
## [Overview](/iron-io/functions/blob/master/OVERVIEW.md)
|
|
|
|
## Quick Start
|
|
|
|
First let's start our IronFunctions API
|
|
|
|
```
|
|
docker run --rm -it -p 8080:8080 iron/functions
|
|
```
|
|
|
|
This command will quickly start our API using the default database `Bolt` running on `:8080`
|
|
|
|
Now that we have our API up and running we can quickly create our first function
|
|
|
|
```
|
|
curl -H "Content-Type: application/json" -X POST -d '{
|
|
"name": "MyRoute"
|
|
"path": "/myroute"
|
|
"image": "iron/hello"
|
|
}' http://localhost:8080/v1/apps/myapp/routes
|
|
```
|
|
|
|
Done. Now you have our first IronFunctions route ready.
|
|
|
|
Now let's test our new route.
|
|
|
|
```
|
|
curl http://localhost:8080/r/myapp/myroute
|
|
```
|
|
|
|
## Configuring your API
|
|
|
|
### Databases
|
|
|
|
These are the current databases supported by IronFunctions:
|
|
|
|
- [Running with BoltDB](/iron-io/functions/blob/master/docs/database/boltdb.md)
|
|
- [Running with Postgres](/iron-io/functions/blob/master/docs/database/postgres.md)
|
|
|
|
## API Usage
|
|
|
|
### Creating applications
|
|
|
|
```sh
|
|
curl -H "Content-Type: application/json" -X POST -d '{
|
|
"name":"APP_NAME"
|
|
}' http://localhost:8080/v1/apps
|
|
```
|
|
|
|
### Creating routes in a application
|
|
|
|
Now add routes to the app. First we'll add a route to the output of a docker container:
|
|
|
|
```sh
|
|
curl -H "Content-Type: application/json" -X POST -d '{
|
|
"name": "hello",
|
|
"path":"/hello",
|
|
"image":"iron/hello"
|
|
}' http://localhost:8080/v1/apps/myapp/routes
|
|
```
|
|
|
|
### Calling your Function
|
|
|
|
```
|
|
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.
|
|
|
|
```sh
|
|
curl -H "Content-Type: application/json" -X POST -d '{
|
|
"name":"Johnny"
|
|
}' http://localhost:8080/r/myapp/hello
|
|
```
|
|
|
|
### Using IronFunctions Hosted by Iron.io
|
|
|
|
Simply point to https://functions.iron.io instead of localhost and add your Iron.io Authentication header (TODO: link), like this:
|
|
|
|
```sh
|
|
curl -H "Authorization: Bearer IRON_TOKEN" -H "Content-Type: application/json" -X POST -d '{"name":"APP_NAME"}' https://functions.iron.io/v1/apps
|
|
```
|
|
|
|
And you'll get an ironfunctions.com host:
|
|
|
|
```
|
|
APP_NAME.USER_ID.ironfunctions.com/PATH
|
|
```
|
|
|
|
## [Examples](/iron-io/functions/blob/master/examples)
|
|
|
|
## Logging
|
|
|
|
TODO
|
|
|
|
## Monitoring
|
|
|
|
TODO
|
|
|
|
## Scaling
|
|
|
|
TODO
|
|
|