NAV
Input Output Javascript

Introduction

Welcome to the Kittn API! You can use our API to access Kittn API endpoints, which can get information on various cats, kittens, and breeds in our database.

We have language bindings in Shell, Ruby, and Python! You can view code examples in the dark area to the right, and you can switch the programming language of the examples with the tabs in the top right.

This example API documentation page was created with DocuAPI, a multilingual documentation theme for the static site generator Hugo.

Authentication

To authorize, use this code:

package main

import "github.com/bep/kittn/auth"

func main() {
	api := auth.Authorize("meowmeowmeow")

	// Just to make it compile
	_ = api
}
require 'kittn'

api = Kittn::APIClient.authorize!('meowmeowmeow')
import kittn

api = kittn.authorize('meowmeowmeow')
# With shell, you can just pass the correct header with each request
curl "api_endpoint_here"
  -H "Authorization: meowmeowmeow"
const kittn = require('kittn');

let api = kittn.authorize('meowmeowmeow');

Make sure to replace meowmeowmeow with your API key.

Kittn uses API keys to allow access to the API. You can register a new Kittn API key at our developer portal.

Kittn expects for the API key to be included in all API requests to the server in a header that looks like the following:

Authorization: meowmeowmeow

Kittens

Get All Kittens

package main

import "github.com/bep/kittn/auth"

func main() {
	api := auth.Authorize("meowmeowmeow")

	_ = api.GetKittens()
}
require 'kittn'

api = Kittn::APIClient.authorize!('meowmeowmeow')
api.kittens.get
import kittn

api = kittn.authorize('meowmeowmeow')
api.kittens.get()
curl "http://example.com/api/kittens"
  -H "Authorization: meowmeowmeow"
const kittn = require('kittn');

let api = kittn.authorize('meowmeowmeow');
let kittens = api.kittens.get();

The above command returns JSON structured like this:

[
  {
    "id": 1,
    "name": "Fluffums",
    "breed": "calico",
    "fluffiness": 6,
    "cuteness": 7
  },
  {
    "id": 2,
    "name": "Max",
    "breed": "unknown",
    "fluffiness": 5,
    "cuteness": 10
  }
]

This endpoint retrieves all kittens.

HTTP Request

GET http://example.com/api/kittens

Query Parameters

Parameter Default Description
include_cats false If set to true, the result will also include cats.
available true If set to false, the result will include kittens that have already been adopted.

Get a Specific Kitten

package main

import "github.com/bep/kittn/auth"

func main() {
	api := auth.Authorize("meowmeowmeow")

	_ = api.GetKitten(2)
}
require 'kittn'

api = Kittn::APIClient.authorize!('meowmeowmeow')
api.kittens.get(2)
import kittn

api = kittn.authorize('meowmeowmeow')
api.kittens.get(2)
curl "http://example.com/api/kittens/2"
  -H "Authorization: meowmeowmeow"
const kittn = require('kittn');

let api = kittn.authorize('meowmeowmeow');
let max = api.kittens.get(2);

The above command returns JSON structured like this:

{
  "id": 2,
  "name": "Max",
  "breed": "unknown",
  "fluffiness": 5,
  "cuteness": 10
}

This endpoint retrieves a specific kitten.

HTTP Request

GET http://example.com/kittens/<ID>

URL Parameters

Parameter Description
ID The ID of the kitten to retrieve

Errors

The Kittn API uses the following error codes:

Error Code Meaning
400 Bad Request – Your request sucks
401 Unauthorized – Your API key is wrong
403 Forbidden – The kitten requested is hidden for administrators only
404 Not Found – The specified kitten could not be found
405 Method Not Allowed – You tried to access a kitten with an invalid method
406 Not Acceptable – You requested a format that isn’t json
410 Gone – The kitten requested has been removed from our servers
418 I’m a teapot
429 Too Many Requests – You’re requesting too many kittens! Slow down!
500 Internal Server Error – We had a problem with our server. Try again later.
503 Service Unavailable – We’re temporarially offline for maintanance. Please try again later.

auth-api

sign in

var data = {
    id: $('#username').val(),
    md5pwd: $.md5($('#password').val()),
};
$.ajax({
    type: "POST",
    url: "/auth/api/login",
    data: JSON.stringify(data),
    dataType: "json",
    contentType: 'application/json',
    success: function (data, status, xhr) {
        if (data.errCode === 200) {
            // 此处添加登录成功后的逻辑
            location.href = "/auth/web/login-next";
        } else if (data.errCode === 404) {
            alert("账号或密码错误,请重新输入!");
        } else {
            alert("服务器错误,请重新输入!");
        }
    },
    error: function (XMLHttpRequest, textStatus, errorThrown) {
        if (XMLHttpRequest.status === 404) {
            alert('服务器错误, 请重试');
        }
    }
});

HTTP Request

POST http://cyber-life.cn/auth/api/login

// The above command request JSON structured like this:
{   
    "id": "thomas@cyber-life.cn",
    "md5pwd": "5b0f32614437fcc9cce6697dacbc96c6"
}

Post Body (JSON)

Parameter Default Description
id true username, email or mobile phone number.
md5pwd true must use the md5 encrypted string, cannot use raw text.
{   
    "errCode": 200,
    "errMsg": "Success",
    "rs": {
        "accessToken": "7f4eb7696a95e27990540a85878fcf57",
        "expiresAt": 1552454027102,
        "tokenType": "Bearer",
        "scope": "all",
        "refreshToken": "05080b238f6156422728cedd19f6a573"
    }
}

Success Response Body (JSON)

Parameter Default Description
errCode 200
errMsg Success
rs SessionTicket
{   
    "errCode": 400,
    "errMsg": "Bad Request"
}
{   
    "errCode": 404,
    "errMsg": "Not Found"
}

Failure Response Body (JSON)

ErrCode ErrMsg Description
400 Bad Request not input uid or md5 encrypted password string.
404 Not Found no this uid in system; or uid and password do not match.

sign up

// The above command request JSON structured like this:
{   
    "id": "thomas@cyber-life.cn",
    "md5pwd": "5b0f32614437fcc9cce6697dacbc96c6",
    "verifyCode": "021689"
}

HTTP Request

POST http://cyber-life.cn/auth/api/register

Post Body (JSON)

Parameter Default Description
id true username, email or phone number.
md5pwd true must use the md5 encrypted string, cannot use raw text.
verifyCode true verify code receive from email or phone.
{   
    "errCode": 200,
    "errMsg": "Success",
    "rs": "5b0f32614437fcc9cce6697dacbc96c6"
}

Success Response Body (JSON)

Parameter Default Description
errCode 200
errMsg Success
rs accountId
{   
    "errCode": 400,
    "errMsg": "Bad Request"
}
{   
    "errCode": 408,
    "errMsg": "Request Time-out"
}
{   
    "errCode": 409,
    "errMsg": "Conflict"
}

Failure Response Body (JSON)

ErrCode ErrMsg Description
400 Bad Request not input uid or md5 encrypted password string or verify code.
408 Request Time-out verifiy code time out.
409 Conflict has no this uid in system.

lost password

// The above command request JSON structured like this:
{   
    "id": "thomas@cyber-life.cn",
    "md5pwd": "5b0f32614437fcc9cce6697dacbc96c6",
    "verifyCode": "021689"
}

HTTP Request

POST http://cyber-life.cn/auth/api/lostpwd

Post Body (JSON)

Parameter Default Description
id true username, email or phone number.
md5pwd true must use the md5 encrypted string, cannot use raw text.
verifyCode true verify code receive from email or phone.
{   
    "errCode": 200,
    "errMsg": "Success"
}

Success Response Body (JSON)

Parameter Default Description
errCode 200
errMsg Success
{   
    "errCode": 400,
    "errMsg": "Bad Request"
}
{   
    "errCode": 404,
    "errMsg": "Not Found"
}
{   
    "errCode": 408,
    "errMsg": "Request Time-out"
}
{   
    "errCode": 412,
    "errMsg": "Precondition Failed"
}

Failure Response Body (JSON)

ErrCode ErrMsg Description
400 Bad Request not input uid or md5 encrypted password string or verify code.
404 Not Found no this uid in system.
408 Request Time-out verifiy code time out.
412 Conflict verifiy code not match.

sign out

HTTP Request

DELETE http://cyber-life.cn/auth/api/logout

{   
    "errCode": 200,
    "errMsg": "Success"
}

Success Response Body (JSON)

Parameter Default Description
errCode 200
errMsg Success