Skip to content
Rubén de Celis Hernández edited this page Oct 20, 2016 · 1 revision

Usage Linkero

It´s highly recommended to install requests library from python, execute:

pip install requests

To import requests functionalities, just import them:

from requests import post
from requests import get
from requests import put
from requests import patch
from requests import delete

Create a new user

This API only allows you to access if you are a identified users. In example:

post ('http://localhost:5000/api/users', data={"username":"ruter106","password":"ruter106","secret":"admin"})

This command will send a post request to URI api/users/ and providing username, password and secret fields with its values.

Getting an access token

Using a token its possible to hide username and password fields from the user accessing with a request like:

get ('http://localhost:5000/api/token', auth=("ruter106", "ruter106")).json()

Using this credential, you can get and json response with a token and its duration in seconds:

{
  "duration": 600,
  "token": "eyJpYXQiOjE0NzE0MzY1NTMsImFsZyI6IkhTMjU2IiwiZXhwIjoxNDcxNDM3MTUzfQ.eyJpZCI6MX0.bu7YvRxsqCRv_1ly9KEd5kJq3BdgmJ5XsCJo0bw2e9I"
}

While token is valid, you can get another one using this request:

get ('http://localhost:5000/api/token', auth=("eyJpYXQiOjE0NzE0MzY1NTMsImFsZyI6IkhTMjU2IiwiZXhwIjoxNDcxNDM3MTUzfQ.eyJpZCI6MX0.bu7YvRxsqCRv_1ly9KEd5kJq3BdgmJ5XsCJo0bw2e9I", "")).json()

Accessing to APIs

To get any data from an API, you must add your credential into the request providing username and password. In example:

get ('http://localhost:5000/todos', auth=("ruter106", "ruter106")).json()

If you need to send some requests or you are using a service connected to the API, using tokens is the best way to do it:

get ('http://localhost:5000/todos', auth=("eyJpYXQiOjE0NzE0MzY1NTMsImFsZyI6IkhTMjU2IiwiZXhwIjoxNDcxNDM3MTUzfQ.eyJpZCI6MX0.bu7YvRxsqCRv_1ly9KEd5kJq3BdgmJ5XsCJo0bw2e9I", "")).json()

Tokens expired in a short period of time, so if a token is stolen, it doesn´t give the original credentiales, its a methor more secure that use the password in all requests. Also, the access with a token is limited in time, and never more time that token´s duration.

Response codes

Linkero is an securized API, and all codes are standard. You can check Design wiki´s page to get more info.

To get the response, just parse propertly the json given with request library. In example:

get ('http://localhost:5000/todos', auth=("ruter106", "ruter106"))

If you get 401 error, you are not properly authenticated.

Clone this wiki locally