add README for HTTP API

This commit is contained in:
afrokick 2020-03-22 00:28:50 +03:00
parent 2bcb27d20b
commit 0a296aba07
3 changed files with 43 additions and 1 deletions

View File

@ -189,6 +189,10 @@ when the peer can no longer be reached.
peerServer.on('disconnect', (client) => { ... });
```
## HTTP API
Read [/src/api/README.md](src/api/README.md)
## Running tests
```sh
@ -218,7 +222,7 @@ $ docker run -p 9000:9000 -d myimage
This will start a peerjs server on port 9000 exposed on port 9000 with key `peerjs` on path `/myapp`.
Open browser with http://localhost:9000/myapp It should returns JSON with name, description and website fields. http://localhost:9000/myapp/peerjs/id - should returns a random string (random client id)
Open your browser with http://localhost:9000/myapp It should returns JSON with name, description and website fields. http://localhost:9000/myapp/peerjs/id - should returns a random string (random client id)
## Problems?

View File

@ -1,5 +1,22 @@
# PeerServer Changelog
### vNEXT 0.5.0
* Change: use "/" instead of "/myapp" as a default value for config's `path` option
* New: typescript declaration file
* Update deps:
```diff
- "cors": "2.8.4",
+ "cors": "^2.8.5",
- "uuid": "3.3.3",
+ "uuid": "^3.4.0",
- "ws": "7.1.2",
+ "ws": "^7.2.3"
```
### 0.4.0
* New: Allow passing in custom client ID generation function - #157 Thanks @ajmar

21
src/api/README.md Normal file
View File

@ -0,0 +1,21 @@
## HTTP API
In progress...
The API methods available on `YOUR_ROOT_PATH` + `path` option from config.
So, the base path should be like `http://127.0.0.1:9000/` or `http://127.0.0.1:9000/myapp/` if `path` option was set to `/myapp`.
Endpoints:
* GET `/` - return a JSON to test the server.
This group of methods uses `:key` option from config:
* GET `/:key/id` - return a new user id. required `:key` from config.
* GET `/:key/peers` - return an array of all connected users. required `:key` from config. **IMPORTANT:** You should set `allow_discovery` to `true` in config to enable this method. It disabled by default.
This group of methods uses `:key` option from config, `:userId` and `:userToken` parameters from user.
* POST `/:key/:userId/:userToken/offer`
* POST `/:key/:userId/:userToken/candidate`
* POST `/:key/:userId/:userToken/answer`
* POST `/:key/:userId/:userToken/leave`