This is a node.js (Express.js
+ Typescript
+ MySQL
) server for a social
application Wenjiu, which has a corresponding Android client.
The main functions of this server are
- to provide a set of HTTP APIs for user activities,
- to schedule timely scanning and send push requests to push notification platform, and
- to store and manage multimedia files on the server disk.
This was firstly written in pure javascript (with --harmony-async-await
),
and later converted to Microsoft's Typescript in consideration of providing
more type security and reducing possible bugs. Due to this conversion,
code styles may have a mysterious (actually, not so mysterious) mixture.
userid
and token
are routinely in the headers while others should be sent
in the body.
-
user registration, [POST] @
/api/users
withusername
(string with length at most 30),password
,- and other optional fields (to be implemented).
-
user login, [POST] @
/api/sessions
withusername
, andpassword
.
-
user logout, [DELETE] @
/api/sessions
withuserid
(integer), andtoken
(string).
-
view basic profile of a user, [GET] @
/api/users/:user_id
withuserid
andtoken
.
-
update profile of a user, [PUT] @
/api/users/:user_id
withuserid
,token
, and- (optional)
gender
('female'
or'male'
), - (optional)
nickname
(string
), - (optional)
signature
(string
within length of 256), - (optional)
figure_id
(int
),
-
reset password for a user, [POST] @
/api/users/:user_id/reset_password
withuserid
,token
,old_password
, andnew_password
.
-
publish a request, [POST] @
/api/requests
withuserid
,token
,title
, (title
is DEPRECATED and should be ignored)text
, andendtime
.- (optional)
multimedia
as a string of JSON array, e.g. "[1,2,3,4]"
-
view a request, [GET] @
/api/requests/:request_id
withuserid
,token
.
-
delete a request, [DELETE] @
/api/requests/:request_id
withuserid
,token
, andrequest_id
.
-
view recent requests, [GET] @
/api/requests
withuserid
, andtoken
.- (optional)
last_time
, a timestamp in ms indicating used as a cursor for request creation time. e.g./api/requests?last_time=1480832617296
. If provided with this parameter, the server will only send back requests created in prior to this time.
-
publish a response, [POST] @
/api/responses
withuserid
,token
,text
, andrequest_id
.- (optional)
multimedia
as a string of JSON array, e.g. "[1,2,3,4]"
-
view a response, [GET] @
/api/responses/:response_id
withuserid
,token
.
-
delete a response, [DELETE] @
/api/responses/:response_id
withuserid
,token
, andresponse_id
.
-
like a response, [POST] @
/api/responses/:response_id/like
withuserid
, andtoken
.
-
view request history, [GET] @
/api/users/requests
withuserid
andtoken
.- (optional)
last_time
, a timestamp in ms indicating used as a cursor for request creation time. e.g./api/users/requests?last_time=1480832617296
. If provided with this parameter, the server will only send back requests created in prior to this time.
-
view response history, [GET] @
/api/users/responses
withuserid
andtoken
.
-
view user history (both requests and responses), [GET] @
/api/users/history
withuserid
, andtoken
.- (optional)
last_time
, as is stated above in request history API.
-
upload a file, [POST] @
/api/multimedia/
withuserid
,token
anddata
(the file to be uploaded).- Hint: make sure the file extension is one of
IMG
,VID
, orSND
, because these will be the identifier for the multimedia types (images, videos, or sounds).
-
download a file, [GET] @
/api/multimedia
withuserid
,token
andfileid
(as a GET query parameter).- (optional) In the header if there is
'imageonly': 'yes'
, then file content will be sent if and only if this file is an image, i.e. with an extension asIMG
. - Hint: For responses, there will be an entry in the header of
'Multimedia-Type': FILE_EXTENTION
. An example of response header is below.
200, OK
Date: Sun, 11 Dec 2016 07:32:00 GMT
Last-Modified: Wed, 07 Dec 2016 16:37:20 GMT
Server: Apache/2.4.7 (Ubuntu)
X-Powered-By: Express
ETag: W/"ae18-158da258188"
Content-Type: application/octet-stream
Multimedia-Type: jpg
Cache-Control: public, max-age=0
Connection: Keep-Alive
Accept-Ranges: bytes
Keep-Alive: timeout=5, max=100
Content-Length: 44568
- fetch dimensions of an image, [GET] @
/api/multimedia/:imageid/dimensions
withuserid
,token
, andimageid
(as a parameter inside of the url).
Responses are in JSON format and have at least two fields:
status
, normally"success"
or"failure"
, andmessage
.
For user login, userid
and token
are also sent back.