Design documents added.
[speedfreak] / documents / API.txt
1 API specifications for client-server communication
2 ==================================================
3
4
5 General information
6 ===================
7
8 This document will briefly describe API that is used in Speed Freak project. 
9 In this document client will be Maemo 5 application running on Nokia N900 device.
10 Server will be PHP application running on api.speedfreak-app.com
11
12 General technical information
13 =============================
14
15 XML will be used for encapsulating data sent to and received from server. XML will
16 be sent using HTTP protocol as POST data. Once product is launched HTTP will be
17 swapped in favor of HTTPS for additional security. 
18
19 All requests sent to server should satisfy following requirements:
20
21 - Login and password supplied via HTTP basic authentication (not required for 
22 registration)
23 - Post field xml should contain XML (not required in login request)
24 - XML should be UTF8 encoded
25
26 Server in return will respond with XML in body of the response if request was
27 successful or with HTTP error code if there was problem processing the request.
28 Successful requests return 200 HTTP status code.
29
30 Here is the list of general errors that client might encounter:
31
32 - 404: Request sent to incorrect URL
33 - 500: General error during processing request
34 - 403: Client has no privileges to access this resource
35 - 400: Invalid request
36 - 401: Failed to authenticate
37
38 Registration process
39 ====================
40
41 URL: /register
42
43 Every single client should register before it can send own measurement results or
44 fetch other's results. During registration client has to supply following information:
45
46 - Login: This is 3-12 charecters long nickname that has to be unique
47 - Password: 6-255 charectors long password
48 - Email: email address that will be used for password recovery etc. Has to be unique.
49
50 Below is example of XML that client might send to server to register an account:
51
52 <?xml version="1.0" encoding="utf-8"?>
53 <user>
54     <login>test827</login>
55     <password>thisisaveryinsecurepassword</password>
56     <email>test@example.com</email>
57 </user>
58
59 If registration is successful server will return 200 HTTP status code along with
60 text "OK" in the response body. In other cases (invalid email, login exists etc)
61 server will return HTTP error code 400 with error message in the body text.
62
63
64 Login
65 =====
66
67 URL: /login
68
69 Because communication with server has no state there is no need to login. Client
70 might need to verify that credentials supplied by user are correct. In order to
71 do that client can send a login request which will just verify that login and password
72 are correct and user exists in database.
73
74 When making a login request you don't have to supply XML, only basic authentication.
75 If credentials are correct server will return "OK" along with HTTP status code 200.
76 In any other case it will return 401 HTTP error code along with error description.
77
78
79 Fetching results
80 ================
81
82 URL: /results/category_name/limit
83
84 Category: For example "acceleration-0-100", "top-speed" and so on
85 Limit: This will tell server how many results you want to get back. Results are
86 ordered by record position starting with highest record first.
87
88 Both parameters are required.
89
90 Below is example of what client might get back in return when sending following
91 request: /results/acceleration-0-100/10
92
93 <?xml version="1.0" encoding="utf-8"?>
94 <results category="acceleration-0-100" unit="seconds" description="Acceleration from 0 to 100 km/h">
95     <result position="1" user="test928" date="12/1/2010" value="13" />
96     <result position="2" user="test922" date="15/1/2010" value="12" />
97     <result position="3" user="test92a" date="11/1/2010" value="11" />
98     <result position="4" user="test92s" date="15/2/2010" value="10" />
99     <result position="5" user="test92d" date="1/1/2010" value="9" />
100     <result position="6" user="test92f" date="31/1/2010" value="8" />
101     <result position="7" user="test92f" date="1/1/2010" value="7" />
102     <result position="8" user="test92g" date="2/1/2010" value="6" />
103     <result position="9" user="test92w" date="3/1/2010" value="5" />
104     <result position="10" user="test92a" date="17/1/2010" value="4" />
105 </results>
106
107
108 Sending results
109 ===============
110
111 URL: /update/category_name
112
113 Category: same as when fetching results
114
115 In order to submit results to server client needs to send XML with measurement results to
116 category that result belongs to. Below is example of XML:
117
118 <?xml version="1.0" encoding="utf-8"?>
119 <result value="14" unit="seconds" date="14/2/2010" />
120
121
122 Logout
123 ======
124
125 There is no need to logout as server is stateless, but client can mimic logout
126 functionality by "forgetting" user credentials on the mobile device.
127