Results 1 to 7 of 7

Thread: RESTFul Webservice with VDF 17.0

  1. #1

    Exclamation RESTFul Webservice with VDF 17.0

    Hey everybody. I'm a little bit lost in my project and I hope somebody here is able to help me.

    I have to develop a RESTFul Webservice and I am still using Visual DataFlex 17.0.
    After reading a couple of Wikipedia articles about the Representational state transfer, the Hypertext Transfer Protocol and also the forum thread about REST APIs and OAuth 2.0, I still don't have quite the right answer/solution for my problem.

    Maybe I understand something wrong. I'm gonna explain my thoughts

    In the HTTP/1.0 specification the methods GET, POST and HEAD were implemented and in the HTTP/1.1 OPTIONS, PUT, DELETE, TRACE and CONNECT were added. To run/develop a RESTFul webservice, I need 4 (GET, PUT, POST, DELETE) out of the 8 HTTP methods. In Visual DataFlex 17.0 there are only 3 (GET, POST and PUT) of 4 (DELETE is missing) methods given. For my project I don't need to delete anything, it's only necessary to create and to submit data, so I only need the GET and POST method. The POST and GET method are both implemented in Visual DataFlex 17.0, so I am able to realize a RESTFul Webservice with VDF 17.0 and only the GET and POST method. Am I right with this theory, or completely wrong?

  2. #2
    Join Date
    Feb 2009
    Location
    West Yorkshire - UK
    Posts
    928

    Default Re: RESTFul Webservice with VDF 17.0

    REST is used to describe everything from an actual RESTFUL architecture to a midpoint where the API includes verbs and identifiers in the main url (e.g. "http://localhost/myapp/user/9000") to anything that returns a JSON structure.

    When you say you need to develop a RESTful architecture, what are you being asked for? Do you just need to provide an API with a JSON interface?

    You only really need two verbs (GET and POST). Use the former for calls that don't change the database. Use the latter for calls that do change the database. VDF 17.0 can be used for GET, and I'm not sure about POST. However. JSON support in version 17.0 isn't the best, and your URL's will be in the form "http://localhost/myapp/products.wso?id=9000"

    Other options:

    - The IIS URL rewrite module could be used to make prettier URL's, and it potentially could be used to implement routing for other request_method verbs.
    - You should investigate Mertech's Evolution (https://www.mertech.com/evolution/), as this is geared quite heavily to supporting JSON APIs.
    Sean Bamforth. - D̤͍͍̭̱̄ͦ̆̏̇ͯ͑̄å̩̻͈͒͌t͇̻͙̞̤̱̏̎̐a͈͎͈ͬ̓̽ͮ̓̔̎ͅf̙͓̃̆̈́̔ ̳̣̝͔̲ḷ̩̺̗͎ͤ͂̇̚e̻̙̼̞̥͖̬̹ͮ͌ͫ̆ͬͅx͉̖̣̩̮̖̎͌ ͍̃̃̉̆̋̋ͥP̠̝̱̿͛ͬͩ̍̅̔ͣr̻̪̤͚̘̰̤͑̿̈̄̍ͯo̫͈̪̭̥͙͛̃̔̀g̔͗ͦ̅ ̝̯̘̣̘͗͆̄̋r̲͓̭͓̪̋ͩͤ͛̑́̎͋a͇̰̼͚̜̅́͌͗̆̅̏ͪͦm̯̤̱̥͇͋͒̈̅̓ͮ ̱̣̞m̖̼̰̟̗̮̬͓͗͋̏̓ͫ̑ͪͅḙ̄ͯͧ̋̋̑̊͗ͅr͕͇ͪ͒̆͗͆̓̀

  3. #3

    Default Re: RESTFul Webservice with VDF 17.0

    Ok my description wasn't fully correct. I don't have to develop a RESTful architecture. A RESTFul architecture is developed and provided by a different company and from them I get an interface, where I have to communicate through my software.

    I have a sample written in C#. Is it possible to realize exactly the same in VDF 17.0 or do I have to upgrade to DF 18.1?

    PHP Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.IO;
    using System.Net;
     
    namespace 
    efstaTest
    {
     class 
    Program
     
    {
      static 
    void Main(string[] args)
      {
       
    string data "";
       
    //Testdaten aus XML-Datei als Text auslesen
       
    if (File.Exists("testdaten.xml"))
        
    data File.ReadAllText("testdaten.xml");
       
    //Text in Bytes konvertieren
       
    byte[] bytes Encoding.UTF8.GetBytes(data);
       
    //Webrequest zum lokalen Register erstellen
       
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://127.0.0.1:5618/register");
     
       
    //ContentType, Länge und Methode für POST-Request setzen
       
    request.ContentType "application/vnd.efsta.efr.v1+xml; encoding='utf-8'";
       
    request.ContentLength bytes.Length;
       
    request.Method "POST";
     
       
    //Über den Requeststream die Daten in den Request schreiben
       
    Stream requestStream request.GetRequestStream();
       
    requestStream.Write(bytes0bytes.Length);
       
    requestStream.Close();
       try
       {
        
    //Request senden und auf Antwort warten
        
    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
        if (
    response.StatusCode == HttpStatusCode.OK)
        {
         
    //Daten aus der Antwort auslesen und auf der Console ausgeben
         
    Stream responseStream response.GetResponseStream();
         
    string responseStr = new StreamReader(responseStream).ReadToEnd();
         
    Console.WriteLine(responseStr);
        }
        else
        {
         
    //Wenn Statuscode nicht OK ist, Statuscode auf Console ausgeben
         
    Console.WriteLine("Statuscode: " response.StatusCode);
        }
       }
       catch (
    Exception e)
       {
        
    //Im Fehlerfall (zB Register nicht erreichbar), Fehler auf der Console ausgeben
        
    Console.WriteLine(e.Message);
       }
       
    Console.ReadLine();
      }
     }


  4. #4
    Join Date
    Feb 2009
    Location
    West Yorkshire - UK
    Posts
    928

    Default Re: RESTFul Webservice with VDF 17.0

    ah - sorry.

    VDF17 has GET and POST. If you need the other verbs, you can either upgrade to VDF18.1 or use a third party http component. I have used the Chilkat components for this - specifically https://www.chilkatsoft.com/HttpActiveX.asp. This works in VDF17.0

    For converting the XML, you can use the XML libraries provided by Data Access, or use an XML Parsing library. (I tend to use my own XML Parsing library (https://bitbucket.org/seanbamforth/xmlparse), but this is probably because I never got on that well with the Data Access libraries.
    Sean Bamforth. - D̤͍͍̭̱̄ͦ̆̏̇ͯ͑̄å̩̻͈͒͌t͇̻͙̞̤̱̏̎̐a͈͎͈ͬ̓̽ͮ̓̔̎ͅf̙͓̃̆̈́̔ ̳̣̝͔̲ḷ̩̺̗͎ͤ͂̇̚e̻̙̼̞̥͖̬̹ͮ͌ͫ̆ͬͅx͉̖̣̩̮̖̎͌ ͍̃̃̉̆̋̋ͥP̠̝̱̿͛ͬͩ̍̅̔ͣr̻̪̤͚̘̰̤͑̿̈̄̍ͯo̫͈̪̭̥͙͛̃̔̀g̔͗ͦ̅ ̝̯̘̣̘͗͆̄̋r̲͓̭͓̪̋ͩͤ͛̑́̎͋a͇̰̼͚̜̅́͌͗̆̅̏ͪͦm̯̤̱̥͇͋͒̈̅̓ͮ ̱̣̞m̖̼̰̟̗̮̬͓͗͋̏̓ͫ̑ͪͅḙ̄ͯͧ̋̋̑̊͗ͅr͕͇ͪ͒̆͗͆̓̀

  5. #5

    Default Re: RESTFul Webservice with VDF 17.0

    Thank you very much. That's exactly what I was looking for, if the GET and POST from VDF17.0 aren't enough.

  6. #6
    Join Date
    Mar 2009
    Location
    Beech Hill - a village near Reading in the UK
    Posts
    2,812

    Default Re: RESTFul Webservice with VDF 17.0

    Mac (?)

    DF 18.1+ is what you need: the new HttpVerbAddrRequest function of the cHttpTransfer class allows you to specify the verb you require (usually one of GET, POST, PUT, PATCH or DELETE).

    Mike

  7. #7
    Join Date
    Mar 2009
    Location
    Beech Hill - a village near Reading in the UK
    Posts
    2,812

    Default Re: RESTFul Webservice with VDF 17.0

    Mac - just to be clear: are you being asked to develop a RESTful web service, or a client for a RESTful web service?

    Mike

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •