nerves_hub_rest_api
所属分类:前端开发
开发工具:Elixir
文件大小:8KB
下载次数:0
上传日期:2016-07-28 05:47:01
上 传 者:
sh-1993
说明: 用于与中心对话的REST API
(REST API for talking with Hub)
文件列表:
CHANGELOG.md (673, 2016-07-28)
LICENSE (563, 2016-07-28)
VERSION (6, 2016-07-28)
lib (0, 2016-07-28)
lib\hub_rest_api.ex (6668, 2016-07-28)
mix.exs (628, 2016-07-28)
mix.lock (1540, 2016-07-28)
test (0, 2016-07-28)
test\hub_rest_api_test.exs (7706, 2016-07-28)
test\test_helper.exs (15, 2016-07-28)
HubRestApi
==========
Implements a REST-based plugin for the Cowboy webserver that allows json-based transactions against hub for state.
## Usage
HubRestApi is a handler for Cowboy. An example that serves up the entire Hub at /hub/.... on port 8080.
```elixir
import Nerves.HubRestApi
dispatch = :cowboy_router.compile [{:_,[
{"/hub/[...]", HubRestApi, %{} }
}]}]
{:ok, _pid} = :cowboy.start_http :http, 10,
[port: 8080],
[env: [dispatch: dispatch] ]
```
## Options
HubRestApi can also take takes a couple options in the options map, as follows:
on_wait_start :: fn/0
Called when a connection is initiated, may return a value which is passed to on_wait_stop.
on_wait_end :: fn/1
Called with the result of on_wait_start, if exists, or false, if not.
json_provider_hook :: fn/1
Allows hooking the responses given by th json_provider and rfc7386_provider Takes a cowboy_req parameter, and returns a modified cowboy_req.
近期下载者:
相关文件:
收藏者: