e_chat_server
所属分类:其他
开发工具:Erlang
文件大小:0KB
下载次数:0
上传日期:2017-07-24 18:21:40
上 传 者:
sh-1993
说明: 简单聊天服务器,
(Simple chat server,)
文件列表:
.ruby-version (6, 2017-07-24)
Capfile (837, 2017-07-24)
Gemfile (111, 2017-07-24)
Gemfile.lock (438, 2017-07-24)
Makefile (335, 2017-07-24)
bin/ (0, 2017-07-24)
bin/migrate.sh (110, 2017-07-24)
config/ (0, 2017-07-24)
config/deploy.rb (1797, 2017-07-24)
config/deploy/ (0, 2017-07-24)
config/deploy/production.rb (2056, 2017-07-24)
config/deploy/staging.rb (2089, 2017-07-24)
deploy/ (0, 2017-07-24)
deploy/ansible.cfg (125, 2017-07-24)
deploy/books/ (0, 2017-07-24)
deploy/books/env.yaml (379, 2017-07-24)
deploy/books/nginx.yaml (534, 2017-07-24)
deploy/books/postgresql.yaml (984, 2017-07-24)
deploy/books/software.yaml (584, 2017-07-24)
deploy/group_vars/ (0, 2017-07-24)
deploy/group_vars/all.yml (497, 2017-07-24)
deploy/inventory (26, 2017-07-24)
deploy/playbook.sh (60, 2017-07-24)
deploy/rollup.sh (239, 2017-07-24)
erlang.mk (198095, 2017-07-24)
migrations/ (0, 2017-07-24)
migrations/001_users.sql (246, 2017-07-24)
migrations/002_rooms.sql (183, 2017-07-24)
migrations/003_users_rooms.sql (134, 2017-07-24)
migrations/004_messages.sql (296, 2017-07-24)
migrations/005_sessions.sql (247, 2017-07-24)
rel/ (0, 2017-07-24)
rel/sys.config.example (871, 2017-07-24)
rel/vm.args (62, 2017-07-24)
relx (164214, 2017-07-24)
relx.config (147, 2017-07-24)
src/ (0, 2017-07-24)
src/e_chat_server.app.src (364, 2017-07-24)
... ...
# e_chat_server
Minimalist chat server written in Erlang/OTP.
## API description
### Login
```
POST /v1/login
{"login":"user", "password":"password"}
HTTP 200 OK
{"session_id":"3da541559918a808c2402bba5012f6c60b27661c"}
HTTP 422 Unprocessable Entity
{"error":{"code":"invalid_json"}}
HTTP 422 Unprocessable Entity
{"error":{"code":"wrong_credentials"}}
HTTP 422 Unprocessable Entity
{"error":{"code":"user_not_found"}}
```
### Logout
```
POST /v1/logout
X-Session-Id: abb8fe30-a3e7-4eee-8afd-f3c2f046f6f0
{}
HTTP 200 OK
{}
HTTP 401 Unauthorized
{"error":{"code":"unauthorized"}}
```
### Registration
```
POST /v1/register
{"login":"user", "password":"password"}
HTTP 200 OK
{"session_id":"3da541559918a808c2402bba5012f6c60b27661c"}
HTTP 422 Unprocessable Entity
{"error":{"code":"invalid_json"}}
HTTP 422 Unprocessable Entity
{"error":{"code":"user_already_exists"}}
```
### Account info
```
GET /v1/info
X-Session-Id: abb8fe30-a3e7-4eee-8afd-f3c2f046f6f0
HTTP 200 OK
{"id":1,"login":"Василий"}
HTTP 401 Unauthorized
{"error":{"code":"unauthorized"}}
```
### Search users
```
GET /v1/users/?q=Вася
X-Session-Id: abb8fe30-a3e7-4eee-8afd-f3c2f046f6f0
HTTP 200 OK
[
{"id": 1,"login": "Вася"}
]
HTTP 401 Unauthorized
{"error":{"code":"unauthorized"}}
```
### Search available rooms
```
GET /v1/rooms
X-Session-Id: abb8fe30-a3e7-4eee-8afd-f3c2f046f6f0
HTTP 200 OK
[
{"id":10,"users":[{"id":2,"login":"Петр"},{"id":1,"login":"Василий"}]}
]
HTTP 401 Unauthorized
{"error":{"code":"unauthorized"}}
```
### Create room
```
POST /v1/rooms
X-Session-Id: abb8fe30-a3e7-4eee-8afd-f3c2f046f6f0
{"users":[{"id":2,"login":"Петр"}]}
HTTP 200 OK
{"id":10,"users":[{"id":1,"login":"Василий"},{"id":2,"login":"Петр"}]}
HTTP 422 Unprocessable Entity
{"error":{"code":"invalid_json"}}
HTTP 401 Unauthorized
{"error":{"code":"unauthorized"}}
```
### Room info
```
GET /v1/rooms/10
X-Session-Id: abb8fe30-a3e7-4eee-8afd-f3c2f046f6f0
HTTP 200 OK
{"id":10,"users":[{"id":2,"login":"Петр"},{"id":1,"login":"Василий"}]}
HTTP 422 Unprocessable Entity
{"error":{"code":"room_not_found"}}
HTTP 401 Unauthorized
{"error":{"code":"unauthorized"}}
```
### Room history
```
GET /v1/rooms/10/messages
X-Session-Id: abb8fe30-a3e7-4eee-8afd-f3c2f046f6f0
HTTP 200 OK
[
{"text":"Привет","user_id":1,"room_id":10,"created_at":"2015-08-05T22:18:45"},
{"text":"И тебе привет","user_id":2,"room_id":10,"created_at":"2015-08-05T22:23:34"}
]
HTTP 401 Unauthorized
{"error":{"code":"unauthorized"}}
```
### WebSocket connection
```
WS /v1/rooms/10/chat?session_id=abb8fe30-a3e7-4eee-8afd-f3c2f046f6f0
```
##### Sending a message
```
{"text":"И тебе привет","user_id":1,"room_id":10,"created_at":"2015-08-06T13:44:07"}
```
##### Receiving a message
```
{"text":"И тебе привет","user_id":1,"room_id":10,"created_at":"2015-08-06T13:44:07"}
```
近期下载者:
相关文件:
收藏者: