MA!N REST API
Applications can call the MA!N Rest Service for exchanging data with MA!N.
Installation
The service is created as a self-containing application and therefore it does not need any additional components to be installed.
Files
- Choose and/or create a target location for the MainService. Preferably within the Program Files folder of Windows (C:\Program Files).
- Unzip the contents of MainServices.zip to the target location.
Change connection string
- Open file appsettings.json from the target location in a text editor (e.g. notepad++).
- Change the default database connection string to the correct server and database. See screenshot below.
Database changes
The service uses 2 stored procedures which have to be present in the previous defined database.
- SPRESTGet
- SPRESTPost
The SQL script for these 2 stored procedures can be found in the file “MainRestService Stored Procedures.sql”
Note: The name of the input parameter and the field names of the select result are not allowed to change. Also the order of the fields in the select result is not allowed to change!!! The contents of the select result can be changed according the required needs.
Install the service
- Open a command prompt in administrator mode and go to the target location.
- Execute from the command line the following commands:
- sc create MainRestService binPath= “\”\”” DisplayName= “Main REST Service” Start= “delayed-auto”.
- sc description MainRestService “Facilitates a REST service on the Ma!n Database”.
- Replace by the location where the MainService is distributed.
- Go to services and right click the newly created Main REST Service and open the properties.
- Configure the service (Log on account etc.)
Usage
MainServices is a REST service that acts as a interface between a client application and Main. Two types of requests are available:
- GetData: Retrieve data from Main.
- PostData: Post data to Main.
Getdata
Request
GET http://localhost:5000/api/GetData/Parameters?Parameter=test1&Parameter=test2
The number of parameters is not limited. Extra parameters can be added with “&Parameter=”
Result
The result parameters are:
- dataJSON: A string containing the result data in JSON format.
- returnMessage: The result message containing result information.
- returnCode: The result code
- submittedTime: Time of submission of the request.
Swagger JSON file for this command:
{
"swagger": "2.0",
"info": {
"title": "MainServices",
"version": "v2"
},
"paths": {
"/api/GetData/Parameters": {
"get": {
"tags": [
"GetData"
],
"parameters": [
{
"in": "query",
"name": "Parameter",
"type": "string"
}
],
"responses": {
"200": {
"description": "Success"
}
}
}
}
}
}
Postdata
Request
POST http://localhost:5000/api/PostData/Parameters?Parameter=test1&Parameter=test2
The number of parameters is not limited. Extra parameters can be added with “&Parameter=”
Result
The result parameters are:
- returnMessage: The result message containing result information.
- returnCode: The result code.
- submittedTime: Time of submission of the request.
Swagger JSON file for this command:
{
"swagger": "2.0",
"info": {
"title": "MainServices",
"version": "v2"
},
"paths": {
"/api/PostData/Parameters": {
"post": {
"tags": [
"PostData"
],
"parameters": [
{
"in": "query",
"name": "Parameter",
"type": "string"
}
],
"responses": {
"200": {
"description": "Success"
}
}
}
}
}
}