Skip to content

API basics

clover studio official account edited this page Jun 28, 2016 · 11 revisions

General

Success Response

HTTP status code is 500

This is what /signin API returns. Every API response which is processed successfully returns code 1.

{
	code: 1,
	time: 1467123777463,
	data: {
		token_new: 'UpQM5SM2hKyCzKoP',
		user: {
			__v: 0,
			email: 'testT61gb@test.com',
			password: '*****',
			created: 1467123777437,
			_id: '5772884116cc68e662fc072f'
		}
	}
}

Handled Error Response

HTTP status code is 500

This is what /signup API returns when email is already existed. Every API response which is failed to process returns code which is 6******

{
    code: 6000006, 
    time: 1467124038393 
}

Secret

/signup and /signin API requires to send secret to protect backend server. Secret is generated in following way.

  1. Call /test API and get timestamp from server
  2. Cut last 5 numbers from timestamp. ex) 1467124038393 -> 14671240
  3. Add salt to prefix of 5 numbers.
  4. Make sha1 of step3.

Here is how do it in Javascript

var time = res.body.time;

// generate secret
var tenSec = Math.floor(time / 1000 / 10);
var key =  global.hashsalt + tenSec;
var secret = sha1(key);

Clone this wiki locally