Llamados a la API

En esta capítulo se detalla como está compuesto la estructura de llamados REST a la API del ISB

La siguiente tabla, indica los parámetros y condiciones que debe cumplir una llamada REST para ingresar correctamente a la API.

Llamando un servicio utilizando Shell Script

#! /usr/bin/ksh
cmd=`LC_TIME=en_US date +"%a, %d %b %Y %H:%M:%S %z`
url="http://172.16.4.10:9080/isb/$1/$2"
user='user'
pass='passowrd'
curl -i -H "Date: $cmd" -H "Authorization: S1SDK $user:$pass" -H "Content-Type: application/json; charset=UTF-8" -H "ApplicationID: 1" -H "ChannelID: 1" -H "User-Agent: SYSOne ISB SDK" -X GET "$url"

Llamando un servicio utilizando Python

Para poder invocarlo correctamente se deberá tener instaladas las siguientes dependencias.

  • Python 2.7
  • Paquete "requests".

Si no se posee instalado el paquete "requests", la forma más sencilla de instalarlo en ubuntu/debian es ejecutar los siguientes comandos:

sudo apt-get install pip
sudo pip install requests

Una vez instaladas estas dependencias bastará con copiar el siguiente script y modificar el servidor, puerto y servicios a utilizar. En el mismo existe un ejemplo de get y post.

import requests
import json
import datetime
import time
from threading import Thread
def test_hardcode_services():
    test_service('http://localhost:8080', '/isb', '/party', '/find')
def test_get_service(api_url, base_url, service, final_service):
    today = datetime.datetime.today()
    format = "%a, %d %b %Y %H:%M:%S"
    date = today.strftime(format) + ' -0300'
    headers = {'Date': date, 'Authorization': 'S1SDK user:password', 'Content-Type': 'application/json; charset=UTF-8', 'ApplicationID':'1', 'ChannelID' : '1', 'User-Agent' :'SYSOne ISB SDK'}
    r = requests.get(api_url+ base_url + service + final_service, headers = headers)
    print r.status_code 
    return r.text

def test_post_service(api_url, base_url, service, final_service, jsonpar):
    today = datetime.datetime.today()
    format = "%a, %d %b %Y %H:%M:%S"
    date = today.strftime(format) + ' -0300'
    headers = {'Date': date, 'Authorization': 'S1SDK user:password', 'Content-Type': 'application/json; charset=UTF-8', 'ApplicationID':'1', 'ChannelID' : '1', 'User-Agent' :'SYSOne ISB SDK'}
    r = requests.post(api_url+ base_url + service + final_service, headers = headers,data=jsonpar)
    print r.status_code 
    return r.text
if __name__ == '__main__':
    result = test_post_service('http://localhost:9092', '/isb', '/gender', '/create', '{"description":"TRV","clientCode":"F","codes":[],"typeImpl":"com.sysone.model.Gender"}')
    print result

    result = test_get_service('http://localhost:9092', '/isb', '/gender', '/list')
    print result

results matching ""

    No results matching ""