Guest User

Untitled

a guest
Mar 14th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.79 KB | None | 0 0
  1. # General API Structure
  2. All request endpoint urls start with `api/`. Data is sent and received as JSON objects. All request data is sent in the request body if not specified otherwise. You should return `200` for success responses and any code that starts with `4` for error responses.
  3.  
  4. Date values should be sent and received as unix timestamps in milliseconds.
  5.  
  6. ## Websocket
  7.  
  8. All live data sent over websocket. We will have a single connection. Thus a data format is necessary to differentiate the data. This is the data format:
  9.  
  10. {
  11. type : string, // camera-stream, firmware-update, etc. We should decide on these.
  12. data : any // Put data here. It can by anything: number, string, object etc.
  13. }
  14.  
  15. ## Camera Stream
  16.  
  17. Camera stream is sent in this format. **We may need to implement an endpoint to start/stop sending stream as it will take lots of bandwidth even if we are not viewing it**. Data format:
  18.  
  19. {
  20. type : 'camera-stream',
  21. data : string // base64 string
  22. }
  23.  
  24. ## System Status
  25.  
  26. System statistics are shown in this format.
  27.  
  28. {
  29. type : 'system-status',
  30. data : {
  31. device : {
  32. cpu : number, // CPU usage. 0 to 100
  33. ram : number, // RAM usage in MB
  34. ramMax : number, // RAM capacity in MB
  35. disk : number, // Disk usage in GB
  36. diskMax : number, // Disk capacity in GB
  37. systemTime : number, // Timestamp in ms,
  38. systemUpTime : number, // In seconds
  39. },
  40. processes : [
  41. {
  42. id : number, // Id/number of the process,
  43. serviceUpTime : number, // In seconds
  44. isRunning : bool
  45. }
  46. ]
  47. }
  48. }
  49.  
  50. ## Firmware Update
  51.  
  52. You can send update related activity logs in these objects. I will show them directly in the ui.
  53.  
  54. {
  55. type : 'firmware-update',
  56. data : string
  57. }
  58.  
  59.  
  60. ## Session Management
  61.  
  62. ### Login
  63.  
  64. **POST** : api/login
  65.  
  66. **Request Data:**
  67.  
  68. {
  69. username : string,
  70. password : string
  71. }
  72.  
  73. **Response Data:** No data needed. Just send session id in cookie with `sessionID` key.
  74.  
  75. ### Logout (Not urgent)
  76.  
  77. **POST** : api/logout
  78.  
  79. **Request Data:** none
  80.  
  81. **Response Data:** none
  82.  
  83. ## Home Page
  84.  
  85. ### Get Home Page Details
  86.  
  87. **GET** : api/home/page
  88.  
  89. **Request Data:** none
  90.  
  91. **Response Data:**
  92.  
  93.  
  94. {
  95. version : string, // Firmware version
  96. city : string,
  97. junction : string, // Junction name
  98. cameras : [{
  99. id : number, // Camera process id
  100. direction : string, // Name of the direction/street
  101. }]
  102. }
  103.  
  104. ## Camera Stream
  105.  
  106. ### Start/Stop Stream
  107.  
  108. Start if value is true, stop if false. Process id is given in the url.
  109.  
  110. You should allow stream from only one process. If there is an active stream when a start request is sent, stop it. Also if a user closes the browser, I cannot send a stop request. You need to end the stream when websocket connection ends.
  111.  
  112. **PUT** : api/stream/:processId/streaming
  113.  
  114. **Request Data:**
  115.  
  116. {
  117. value : bool
  118. }
  119.  
  120. **Response Data:** no data
  121.  
  122. ### Set Stream Quality
  123.  
  124. Set quality for current session. I may start and stop streams. All of them should use the same quality value until websocket connection ends.
  125.  
  126. **PUT** : api/stream/:processId/quality
  127.  
  128. **Request Data:**
  129.  
  130. {
  131. value : number // From 0 to 100
  132. }
  133.  
  134. **Response Data:** no data
  135.  
  136. ## Settings
  137.  
  138. ### Get Settings
  139.  
  140. **GET** : api/settings
  141.  
  142. **Request Data:** none
  143.  
  144. **Response Data:**
  145.  
  146. {
  147. time : Object, // An object containing all time settings
  148. network : Object // An object containing all network settings
  149. }
  150.  
  151. ### Set Time Settings
  152.  
  153. **PUT** : api/settings/time
  154.  
  155. **Request Data:** An object containing time settings
  156.  
  157. **Response Data:** none
  158.  
  159. ### Set Network Settings
  160.  
  161. **PUT** : api/settings/network
  162.  
  163. **Request Data:** An object containing network settings
  164.  
  165. **Response Data:** none
  166.  
  167. ### Reset to Factory Settings
  168.  
  169. **POST** : api/settings/reset
  170.  
  171. **Request Data:** none
  172.  
  173. **Response Data:** none
  174.  
  175. ## Device Management
  176.  
  177. ### Get Management Page Details
  178.  
  179. **GET** : api/management/page
  180.  
  181. **Request Data:** none
  182.  
  183. **Response Data:**
  184.  
  185. {
  186. processes : [{
  187. id : number,
  188. direction : string, // Direction of the camera
  189. isRunning : bool
  190. }]
  191. }
  192.  
  193. ### Upload New Firmware
  194.  
  195. Uploads given file as firmware
  196.  
  197. **PUT** : api/firmware
  198.  
  199. **Request Data:**
  200.  
  201. Data format is FormData. File is sent in `file` property.
  202.  
  203. **Response Data:** none
  204.  
  205. ### Restart Device
  206. It would be better if you send the response first, then restart the device. Otherwise I cannot know if operation failed or succeeded.
  207.  
  208. **POST** : api/device/restart
  209.  
  210. **Request Data:** none
  211.  
  212. **Response Data:** none
  213.  
  214. ### Restart Process
  215. It would be better if you send the response first, then restart the device. Otherwise I cannot know if operation failed or succeeded.
  216.  
  217. **POST** : api/processes/:processId/restart
  218.  
  219. **Request Data:** none
  220.  
  221. **Response Data:** none
  222.  
  223. ### Get Logs
  224.  
  225. You can view or download logs by using this endpoint. `download` parameter will decide this.
  226.  
  227. **GET** : api/logs
  228.  
  229. **Request Data:** Send as query parameters
  230.  
  231. {
  232. start : number, // start date. timestamp in ms
  233. end : number, // end date. timestamp in ms
  234. process : number, // process id
  235. limit : number, // number of logs requested for pagination
  236. skip : number, // number of logs to skip for pagination
  237. download : boolean // If true download file, if false send results as json response
  238. }
  239.  
  240. **Response Data:**
  241.  
  242. [{
  243. We need to decide this
  244. }]
  245.  
  246. ## Processes (Cameras)
  247.  
  248. ### Get Process Settings
  249.  
  250. **GET** : api/processes/:processId/settings
  251.  
  252. **Request Data:** None
  253.  
  254. **Response Data:** An object containing process settings
  255.  
  256. ### Update Process Settings
  257.  
  258. **PUT** : api/processes/:processId/settings
  259.  
  260. **Request Data:** An object containing process settings
  261.  
  262. **Response Data:** An object containing processff settings
  263.  
  264. ### Get Process Photos
  265.  
  266. **GET** : api/processes/:processId/photos
  267.  
  268. **Request Data:** Sent as query parameters
  269.  
  270. {
  271. limit : number, // Number of photos to return, for pagination
  272. skip : number, // Number of photos to skip, for pagination
  273. }
  274.  
  275. **Response Data:**
  276.  
  277. {
  278. // We should talk about this
  279. }
  280.  
  281. ### Get Process Videos
  282.  
  283. **GET** : api/processes/:processId/videos
  284.  
  285. **Request Data:** Sent as query parameters
  286.  
  287. {
  288. limit : number, // Number of videos to return, for pagination
  289. skip : number, // Number of videos to skip, for pagination
  290. }
  291.  
  292. **Response Data:**
  293.  
  294. {
  295. // We should talk about this
  296. }
  297.  
  298. ### Delete Process Video
  299.  
  300. **DELETE** : api/processes/:processId/videos/:videoId
  301.  
  302. **Request Data:** none
  303.  
  304. **Response Data:** none
  305.  
  306. ### Create Schedule to Record Video
  307.  
  308. **POST** : api/processes/:processId/video-schedules
  309.  
  310. **Request Data:**
  311.  
  312. {
  313. start : number, // timestamp in ms. recording should start at this moment
  314. end : number, // timestamp in ms. recording should stop at this moment
  315. type : string // Recording type
  316. }
  317.  
  318. **Response Data:**
  319.  
  320. {
  321. id : number, // You should put id or any idendification info on these so that we can delete or update them
  322. start : number,
  323. end : number
  324. }
  325.  
  326. ### Delete Schedule
  327.  
  328. Can we delete a schedule while video is being recorded at that time?
  329.  
  330. **DELETE** : api/processes/:processId/video-schedules/:scheduleId
  331.  
  332. **Request Data:** none
  333.  
  334. **Response Data:** none
  335.  
  336. ## Centris Related Settings
  337.  
  338. ### Get All Centris Related Settings
  339.  
  340. **GET** : api/centris-settings
  341.  
  342. **Request Data:** none
  343.  
  344. **Response Data:**
  345.  
  346. {
  347. device : object, // An object containing device level settings
  348. processes : [{
  349. id : number, // Id of the process
  350. settings : object, // An object containing process settings
  351. rois : [{
  352. regions : [{
  353. points : [ [x1, y1], [x2, y2] ... ],
  354. countingLine : [ [x1, y1], [x2, y2] ],
  355. weigh : number,
  356. laneCount : number
  357. }]
  358. }]
  359. }]
  360. }
  361.  
  362. ### Set Centris Device Settings
  363.  
  364. **PUT** : api/centris-settings/device
  365.  
  366. **Request Data** : An object containing device level settings
  367.  
  368. **Response Data** : An object containing device level settings
  369.  
  370. ### Set Centris Process Settings
  371.  
  372. **PUT** : api/centris-settings/processes/:processId
  373.  
  374. **Request Data** : An object containing process level settings
  375.  
  376. **Response Data** : An object containing process level settings
  377.  
  378. ## PTS Settings
  379.  
  380. ### Get PTS Settings
  381.  
  382. **GET** : api/pts-settings
  383.  
  384. **Request Data** : none
  385.  
  386. **Response Data** :
  387.  
  388. {
  389. device : object, // An object containing device level settings
  390. processes : [{
  391. id : number, // Process settings
  392. settings : object // An object containing process settings
  393. }]
  394. }
  395.  
  396. ### Set PTS Device Settings
  397.  
  398. **PUT** : api/pts-settings/device
  399.  
  400. **Request Data** : An object containing device level settings
  401.  
  402. **Response Data** : An object containing device level settings
  403.  
  404. ### Set PTS Process Settings
  405.  
  406. **PUT** : api/pts-settings/processes/:processId
  407.  
  408. **Request Data** : An object containing process level settings
  409.  
  410. **Response Data** : An object containing process level settings
  411.  
  412. ## Meta Data
  413.  
  414. ### Get Meta Data For a Form
  415.  
  416. Form name is sent in the url. It can be one of these values : `time`, `network`, `process`, `centris`, `pts`.
  417. I will create the initial versions of these pages. You can modify them whenever you need.
  418.  
  419. **GET** : api/meta-data/:formName
  420.  
  421. **Request Data** : none
  422.  
  423. **Response Data** : An object containing form metadata
Add Comment
Please, Sign In to add comment