GSD REST API Sample requests guide


You're able to execute request to net-api using cURL. cURL is a free, open-source software used to transfer data using Internet Protocols for the given URL. You can execute requests using command line in windows operation system or execute it in your own application. The way of using cURL on your own application, depends on technology which you use to create your app. Below you can see sample requests to net-api webservice. You can just pass those commands to the command prompt in operation system, set the values and then run.
CURL documentation

/v1/login

First, you should login to the application. In the response you should get sessionId and you'll be able to execute more requests

1
curl --insecure -XPOST -H "Content-type:application/json" -H "appkey:123" -d "{\"user\":\"yourUserName\",\"pass\":\"yourEncryptedPassword\",\"appNames\":\"yourAppName\"}" "http://localhost:8080/v1/login/"

/v1/object

After login, you've gotten sessionId in the response, so you can execute another requests e.g. get object from the database

1
curl --insecure -XGET -H "appkey:123" -H "sessionId:yourSessionId" "http://localhost:8080/v1/object/yourObjectId"

/v1/execute/{macroName}

1
curl --insecure -XPOST -H "appkey:123" -H "sessionId:yourSessionId" "http://localhost:8080/v1/execute/yourMacroName"

/v1/objects

1
curl --insecure -XGET -H "appkey:123" -H "sessionId:yourSessionId" "http://localhost:8080/v1/object/yourClassName"

/v1/logout

1
curl --insecure -XPOST -H "appkey:123" -H "sessionId:yourSessionId" "http://localhost:8080/v1/logout/" 

/v2/login/secure/key

Request which returns application public RSA key

1
curl --insecure -XGET -H "appkey:123" "http://localhost:8080/v2/login/secure/key"

/v2/login/secure

Login with encrypted credentials

1
curl --insecure -XPOST -H "Content-Type:application/json" -H "appkey:123" -d "{\"credentials\":\"yourCredentials\",\"publickey\":\"yourPublicKey\"}" "http://localhost:8080/v2/login/secure/"

Axios

Below you can see sample JavaScript code to make a HTTP request using axios library. Axios allow programmer to make a HTTP request both from the browser and node.js application.
Axios documentation

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
const config = { 
    headers: { 'Content-Type': 'application/json', 'appKey': 123 }
}

axios.post('http://localhost:8080/v1/login/', { user: 'yourUserName', pass: 'yourEncryptedPassword', appNames: 'yourAppName' }, config)
.then(function (response) {
    console.log(response);
})
.catch(function (error) {
    console.log(error);
})
.finally(function () {

});

Sample macros

Sample macro for serialization

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
VOID xRestApi_BuildSerialization( DBOBJECT obj, HJSON &objectJson )

  IF( objectJson == NULL )
    objectJson.Construct( TRUE );
  ENDIF

  objectJson.GetMember( "Name", TRUE ).SetString( obj.GetString( "Name" ) );
  objectJson.GetMember( "ShowFirstFileDoc", TRUE ).SetBool( obj.GetBool( "ShowFirstFileDoc" ) );

RETURN();

Sample macro for querying data

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
BOOL xRestApi_FindObjects( ObjectSet &objectSet )

  ObjectAllSet allObjects;
  BOOL result = TRUE;
  STRING query, filteredValue = "filteredValue";

  query = "query Name = " + filteredValue + ";";

  IF( !allObjects.Query( query, objectSet ) )
    result = FALSE;
  ENDIF

RETURN( result )