소스 검색

Update README.md to include API specification

Matt Coles 9 년 전
부모
커밋
1e5894c839
1개의 변경된 파일51개의 추가작업 그리고 0개의 파일을 삭제
  1. 51 0
      README.md

+ 51 - 0
README.md

@@ -10,3 +10,54 @@ Then start the Express framework using:
10 10
 ```
11 11
 node index.js
12 12
 ```
13
+
14
+# API
15
+
16
+### /hello/:name/
17
+Returns "Hello :name!" or simply "Hello World!" if no name is present. :)
18
+
19
+### /register/
20
+In order to register a new user account, a `POST` request should be sent, with
21
+the following data:
22
+```
23
+{
24
+    "user": desired_username_here,
25
+    "password": desired_password_here
26
+}
27
+```
28
+The server will then respond with a JSON object that looks something like this:
29
+```
30
+{
31
+    "registered": 1, // Value is 1 or 0 based on whether registration was
32
+    successful
33
+    "auth-key": $2a$10$.X9YrNyd2R7b2ycAumHn.ONiINs2bCkRDupugu6sjZkUkPmXSaSra, //
34
+    Value is an authentication key to be used in API requests
35
+    "error": 0 // Error code, if an error occured. 0 indicates no error.
36
+}
37
+```
38
+The value of the error code will be `1` if the username already exists.
39
+
40
+### /login/
41
+In order to log into an account, or essentially request a new authentication
42
+token, a `POST` request should be sent with the following data:
43
+```
44
+{
45
+    "user": username_here,
46
+    "password": password_here, // Optional field if auth-key is present
47
+    "auth-key": auth_key_here // Optional field if password is present
48
+}
49
+```
50
+Using the auth-key will reset and generate a new authentication key, whereas
51
+password will simply get the current auth-key. In either case the following data
52
+will be returned:
53
+```
54
+{
55
+    "logged_in": 1, // Value is 1 or 0 whether or not the login was successful
56
+    "auth-key": $2a$10$.X9YrNyd2R7b2ycAumHn.ONiINs2bCkRDupugu6sjZkUkPmXSaSra, //
57
+    Only present if logged_in == 1, to be used in API requests
58
+    "error": 0 // Error code, if an error occured. 0 indicates no error.
59
+}
60
+```
61
+The error codes are as follows, 1 indicates the username could not be found, 2
62
+indicates that the password is invalid and 3 indicates the provided
63
+authentication key was invalid.