Please enable JavaScript to view this site.

Navigation: Advanced topics > Programming topics > ASPRunner.NET's REST API

REST API: insert

Scroll Prev Next More

Inserts a record into the database table via POST request.

 

Data is passed as key-value pairs in the body of the request. Fields to be inserted are sent as fieldname=value&fieldname1=value1 list. Similar to update except you do not need to supply editid1 parameter.

 

Arguments
 

table

the table name.

action

insert

field1, field2, ...

field values to update the record

Example

 

Add a category named Beer with description Beer and stuff.

 

curl -X POST "http://localhost:8086/api/v1?table=categories&action=insert" -d "CategoryName=Beer&Description=Beer and stuff" -H "Content-Type: application/x-www-form-urlencoded"  

 

And response will contain the whole new record including the autoincrement column:

 

{  
  "success":true,  
  "data":{  
    "CategoryName":"Beer",  
    "Description":"Beer and stuff",  
    "CategoryID":272  
  }  
}  

 

Sample code

 

Inserts a record into categories table.

 

<?php
$curl = curl_init();
curl_setopt_array($curl, array(
 CURLOPT_URL => "http://localhost:8086/api/v1?table=categories&action=insert",
 CURLOPT_RETURNTRANSFER => true,
 CURLOPT_ENCODING => "",
 CURLOPT_MAXREDIRS => 10,
 CURLOPT_TIMEOUT => 0,
 CURLOPT_FOLLOWLOCATION => true,
 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
 CURLOPT_CUSTOMREQUEST => "POST",
 CURLOPT_POSTFIELDS => array('CategoryName' => 'Beer','Description' => 'Beer and stuff'),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
?>  

 

 

C# code (using RestCharp):

 

var client = new RestClient("http://localhost:8086/api/v1?table=categories&action=insert");
client.Timeout = -1;
var request = new RestRequest(Method.POST);
request.AlwaysMultipartFormData = true;
request.AddParameter("CategoryName", "Beer");
request.AddParameter("Description", "Beer and stuff");
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);

 

JavasScript code (jQuery):

 

var form = new FormData();
form.append("CategoryName", "Beer");
form.append("Description", "Beer and stuff");
 
var settings = {
"url": "http://localhost:8086/api/v1?table=categories&action=insert",
"method": "POST",
"timeout": 0,
"processData": false,
"mimeType": "multipart/form-data",
"contentType": false,
"data": form
};
 
$.ajax(settings).done(function (response) {
 console.log(response);
});