Skip to content

Commit

Permalink
Merge pull request #67 from ganmacs/add-title-to-http_server_helper
Browse files Browse the repository at this point in the history
Add title arguments
  • Loading branch information
repeatedly authored Jul 12, 2019
2 parents bf576b9 + 240e566 commit 2de0174
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions developer/api-plugin-helper-http_server.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module Fluent::Plugin
super

# 2. create and start http server
create_http_server(addr: @bind, port: @port, logger: log) do |serv|
create_http_server(:example_http_server, addr: @bind, port: @port, logger: log) do |serv|
# define endpoint `/hello` with GET method
serv.get('/hello') { [200, { 'Content-Type' => 'text/plain' }, 'hello!'] }
end
Expand All @@ -36,10 +36,11 @@ in plugin's `stop` method. The plugin stops launched http server automatically.

## Methods

### create\_http\_server(addr:, port:, logger:, default\_app: nil, &block)
### create\_http\_server(title, addr:, port:, logger:, default\_app: nil, &block)

This method creats and runs http server with given routes which are defined in `&block`.

- `title`: the name of listen thread. this name must be unique
- `addr`: Adderess to listen to
- `port`: Port to listen to
- `logger`: Logger which is used in server helper
Expand All @@ -48,7 +49,7 @@ This method creats and runs http server with given routes which are defined in `
## Define other HTTP methods

```rb
create_http_server(addr: @bind, port: @port, logger: log) do |serv|
create_http_server(:example_http_server, addr: @bind, port: @port, logger: log) do |serv|
# define POST method `/hello`
serv.post('/hello') { [200, { 'Content-Type' => 'text/plain' }, 'hello!'] }

Expand Down Expand Up @@ -81,7 +82,7 @@ http server helper expects an array as return value like below.
#### Example of recieving json request and return json response

```rb
create_http_server(addr: @bind, port: @port, logger: log) do |serv|
create_http_server(:example_json_http_server, addr: @bind, port: @port, logger: log) do |serv|
serv.post('/hello.json') do |req|
body = JSON.parse(req.body)
log.info(body)
Expand Down

0 comments on commit 2de0174

Please sign in to comment.