JSON API – Testing

To aid in testing and discoverability, any GET APIs will output the result with indentation and with inline hyperlinks for navigation when accessed from a browser. Additionally requests will exclude the application/vnd.api+json content-type so that browsers will render the content rather than presenting as a download.

Testing Functions

Create Testing Form

Function to create a testing form.

POST @apiroot/testing/setup?form=<<form name>>

Example Request

EMPTY

Example Response

{
	"data": {
		"form": << Generated test form name as a string >>
	}
}

The form that has been generated will have one field of each datatype, named for their type:

  • Number
  • String
  • DateTime
  • Boolean
  • Any

CURL Scripts for Testing

This section includes simple illustrative command line calls to the cURL utility commonly found in unix/linux environments. You can install this on windows through Cygwin.

Create a testing form called ‘testform’:

curl --data "" --basic -u testuser:password http://localhost:5150/r/api/json/1.0/testing/setup?form=testform

Create a record:

curl --data '{ "data": { "type": "record", "attributes": { "content": [ { "LineNumber": 1, "Number": 1, "String": "string content", "DateTime": "2016-02-02", "Boolean": true } ] } } }' --basic -u testuser:password "http://localhost:5150/r/api/json/1.0/records/testform"

Update a record:

curl --request PATCH --data '{ "data": { "attributes": { "content": [ { "LineNumber": 1, "Number": 2, "String": "string content UPDATED", "DateTime": "2010-02-02", "Boolean": false } ] } } }' --basic -u testuser:password "http://localhost:5150/r/api/json/1.0/records/testform/3"

Delete a record:

curl --request DELETE --basic -u testuser:password "http://localhost:5150/r/api/json/1.0/records/testform/9"

Attach a file:

curl --data 'DUMMY DATA' --basic -u test:testtest "http://localhost:5150/r/api/json/1.0/records/testform/3/attachments/content/test.txt"

List attachments:

curl --basic -u testuser:password "http://localhost:5150/r/api/json/1.0/records/testform/3"

Get attachment list:

curl --basic -u testuser:password "http://localhost:5150/r/api/json/1.0/records/testform/3/attachments"

Set parent:

curl --request PATCH --data '{ "data": { "type": "record", "id": "testform/1" } }' --basic -u testuser:password "http://localhost:5150/r/api/json/1.0/records/testform/3/relationships/parent"

Clear parent:

curl --request PATCH --data '{ "data": null }' --basic -u testuser:password "http://localhost:5150/r/api/json/1.0/records/testform/3/relationships/parent"

View parent:

curl --basic -u testuser:password "http://localhost:5150/r/api/json/1.0/records/testform/3/relationships/parent"

Get a tabular report:

curl --basic -u testuser:password "http://localhost:5150/r/api/json/1.0/recordrows/

Related Articles