Skip to content

ArtifyCZ/secrethitler

Repository files navigation

Secrethitler

GraphQL Client

  • Path: http://127.0.0.1:8000/graphql/v1
  • Header: Authorization: <token>

API

Create a new anonymous account

  • Method: POST
  • Path: /auth/anonymous
  • Header: Content-Type: application/json
  • body:
{"username": "<name>"}
Curl
curl 'http://127.0.0.1:8000/auth/anonymous' -X POST -H 'Content-Type: application/json' -H 'Authorization: None' --data-raw '{"username":"<name>"}'
HTTP Request
POST /auth/anonymous HTTP/1.1
Host: 127.0.0.1:8000
Content-Type: application/json
Authorization: None
Content-Length: 19

{
	"username":"name"
}

Response:

{
	"id":"947e37e5-3e7f-44a3-b7a6-d678f69f5e81",
	"nickname":"<name>",
	"token":"400a6569-c4a9-467f-8fa5-97214eab6026"
}

Create new game slot

  • Using GraphQL mutation
  • Method: POST
  • Path: /graphql/v1
  • Header: Content-Type: application/json
  • Header Authorization with token received from login
  • body:
{
	"operationName":null,
	"variables":{
		"nPlayers":5
	},
	"query":"mutation CreateSlot($nPlayers: Int!) {  __typename\n  createSlot(players: $nPlayers) {\n    __typename\n    uuid\n  }\n}"
}
GraphQL
mutation {
    createSlot(players: 5) {
        uuid
    }
}
HTTP Request
POST /graphql/v1 HTTP/1.1
Host: 127.0.0.1:8000
Content-Type: application/json
Authorization: 400a6569-c4a9-467f-8fa5-97214eab6026
Content-Length: 182

{
	"operationName":null,
	"variables":{
		"nPlayers":5
	},
	"query":"mutation CreateSlot($nPlayers: Int!) {  __typename\n  createSlot(players: $nPlayers) {\n    __typename\n    uuid\n  }\n}"
}

Response:

{
	"id":"947e37e5-3e7f-44a3-b7a6-d678f69f5e81",
	"nickname":"<name>",
	"token":"400a6569-c4a9-467f-8fa5-97214eab6026"
}

Subscribe to game events

  • Using GraphQL subscription
  • WebSockets (currently ws:// protocol, in the future wss:// encrypted protocol)
  • ws://127.0.0.1:8000/graphql/v1/websocket
  • Header Authorization with token received from login (sent with WS initial payload, not via HTTP headers)
  • Initial WebSocket link payload:
{"Authorization": "<token>"}
GraphQL
subscription Game($uuid: String!){
    game(uuid: $uuid) {
        hello
    }
}
HTTP Request
GET /graphql/v1/websocket HTTP/1.1
Host: 127.0.0.1:8000
Sec-WebSocket-Version: 13
Sec-WebSocket-Protocol: graphql-ws
Sec-WebSocket-Key: 26i09MP46HbbYIQhQPZJdQ==
Upgrade: websocket

Websockets:

{"type":"connection_init","payload":{"Authorization":"1dc0e1d8-a54e-4cff-b3d0-14e5d7aa2269"}}
{"type":"start","id":"87499fcf-9447-46e8-9070-7ce5a916bc04","payload":{"operationName":null,"variables":{"uuid":"fa74c486-6ae9-45dc-90b5-e78b2b5d3ff5"},"query":"subscription Game($uuid: String!) {\n  game(uuid: $uuid) {\n    __typename\n    hello\n  }\n}"}}

Response websockets:

{"type":"data","id":"87499fcf-9447-46e8-9070-7ce5a916bc04","payload":{"data":{"game":{"__typename":"Round","hello":"world"}}}}

Logout

  • Method: DELETE
  • Path: /auth
  • Header Authorization with token received from login
Curl
curl 'http://127.0.0.1:8000/auth' -X DELETE -H 'Authorization: 1dc0e1d8-a54e-4cff-b3d0-14e5d7aa2269'
HTTP Request
DELETE /auth HTTP/1.1
Host: 127.0.0.1:8000
Authorization: 400a6569-c4a9-467f-8fa5-97214eab6026

Response:

  • 204 No Content

Verify session

  • not mandatory
  • Method: GET
  • Path: /auth
  • Header Authorization with token received from login
Curl
curl 'http://127.0.0.1:8000/auth' -H 'Authorization: 1dc0e1d8-a54e-4cff-b3d0-14e5d7aa2269'
HTTP Request
GET /auth HTTP/1.1
Host: 127.0.0.1:8000
Authorization: 400a6569-c4a9-467f-8fa5-97214eab6026

Response:

{
	"id":"947e37e5-3e7f-44a3-b7a6-d678f69f5e81"
}

Get API version

  • not mandatory
  • Method: GET
  • Path: /graphql/version
Curl
curl 'http://127.0.0.1:8000/graphql/version'
HTTP Request
GET /graphql/version HTTP/1.1
Host: 127.0.0.1:8000

Response:

v1

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published