NetTalk Central

NetTalk Web Server => Web Server - Share Knowledge => Topic started by: DonRidley on January 14, 2019, 03:34:26 AM

Title: Get data from your NetTalk server - It's in the doc's! - An API FYI
Post by: DonRidley on January 14, 2019, 03:34:26 AM
Hello All,

Those who have been using NetTalk's API functionality are probably aware of what I am about to describe.  However, for those new to NetTalk or new to using API's, this post is for you.

We often find ourselves in the position of developing an application needing access to data on a web server.  The application could be a desktop, mobile, or web based app.  One reaches a point in the development process where you need to contruct a request for that data.  The request could be SOAP, REST, Javascript, or using a NetWebClient.  If you're new to this, you may not know how to construct these requests.  Enter the NetTalk API server's auto generated documentation.

If your follow the documentation for creating a NetTalk API server you can easily create this ability in just a few minutes.  The NetTalk NetWebService/NetWebServiceMethod templates automatically create documentation for your API requests.  This documentation is easily accessed via a URL. 

Here's some examples from my NetTalk API server:

A Javascript POST request with JSON response:

function syncdevicelocations_getjson(host,urldata,result){
  fetch(host + "/syncdevicelocations" +"?" + urldata, {
    credentials: "include",
    headers: {
      "Accept": "application/json;",
    }
  }).then(function(response){ // get the text out of the reply
    return response.text()
  }).then( function(text){
    // do something with the text reply
  })
}
var host = "https://xxxx.xxxxxxxxxxx.com"

Same request using NetWebClient:

net.ContentType = 'application/json'
net.SetAccept('application/json')
net.Post('https://xxxxxx.xxxxxxxxx.com/syncdevicelocations',jsonData)

My point is that you don't have to guess as to how to construct your request.  NetTalk tells you how to construct it!  That pretty darn cool in my book! 

As I said, many are familiar with this, but hopfully this will save some time and headaches for the API newbies.

Take care and have fun with your NetTalk API server!

Don