3 com.noccy.apiclient
Christopher Vagnetoft edited this page 2021-12-15 13:37:54 +01:00

ApiClient Plugin

Installation

Global installation (recommended, requires SPARK_PLUGINS environment):

  1. Extract the plug into your global plugin directory ($SPARK_PLUGINS)
  2. Go to your project directory and run spark plugin --enable com.noccy.apiclient

Local installation:

  1. Extract the directory into .spark/plugins, like a savage.

Creating catalogs and requests

$ spark api:catalog --create myapp baseurl=http://127.0.0.1/app/ info="MyApp API"
$ spark api:request --save myapp.ping url=v2/ping info="Ping the server" http.header.X-Special=magic

Requests are performed with the api:request command:

$ spark api:request myapp.ping

ApiClient works on a map of properties, populated with the defaults from the catalog. The request properties are then appied, followed by the profile properties.

Properties

## Core properties
#  What protocol to use
protocol={"http"|"websocket"|"xmlrpc"|"jsonrpc"}
#  Final URL is [urlbase+]url
urlbase={url}
url={url}
#  Control logging
log={"yes"|"no"|"auto"}
#  Log bucket, default is 'default'
logfile={name}

## Authentication options
#  Username and password, for basic authentication
auth.username={username}
auth.password={password}
#  Token, for bearer authentication
auth.token={token}
#  If there is ever a need to be explicit
auth.type={"auto"|"basic"|"bearer"}

## HTTP options
#  HTTP request method
http.method={"GET"|"POST"|...}
#  HTTP request version
http.version={"1.0"|"1.1"|"2.0"}
#  HTTP request header
http.header.{name}={value}
#  HTTP query string field
http.query.{field}={value}
#  HTTP POST body
http.body={raw-body}
#  HTTP POST body as json or object
http.body.json={object}

## RPC options
#  The method to invoke for XmlRpc and JsonRpc
rpc.method={string}
#  Set argument by index or name
rpc.argument.{index}={value}

## Request handling
#  Follow HTTP redirects?
request.follow-redirects={"auto"|"no"|"yes"}
#  Max number of redirects to follw
request.max-redirects={number}

## Response handling
#  Parse the response, for readability
response.parse={"none"|"json"|"yaml"|"xml"}  
#  Response codes that are considered good
response.good="200,201,202,203,204,205,206,207,208"