Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

How to create REST API POST working in Alpha WAS

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How to create REST API POST working in Alpha WAS

    Solved, I remove the P type

    Code:
    define class REST::myRestAPI 
    function createNewCustomer as p (newCustomer as REST::myRestAPI::newCustomer)
        dim CustomerID as c = newCustomer.CustomerID
        dim CompanyName as c = newCustomer.CompanyName
        dim ContactName as c = newCustomer.ContactName    
        dim ContactTitle as c = newCustomer.ContactTitle
    
    	dim cn as sql::connection
    	dim flag as l 
    	flag = cn.open("::Name::northwind")
    	if flag = .f. then 
    		'there was an error
    		dim errorText as c 
    		errorText = cn.callresult.text
    		end
    	end if 
    	'turn on portable SQL
    	cn.PortableSQLEnabled = .t.
    	dim SQL as c 
    	sql = "INSERT INTO customers(CustomerID,CompanyName,ContactName,ContactTitle) VALUES (:CustomerID,:CompanyName,:ContactName,:ContactTitle)"
    	dim args as sql::arguments
    	args.add("CustomerID",CustomerID)
    	args.add("CompanyName",CompanyName)
    	args.add("ContactName",ContactName)
    	args.add("ContactTitle",ContactTitle)
    	'execute the SQL
    	flag = cn.execute(sql,args)
    	if flag = .f. then 
    		'there was an error
    		dim errorText as c 
    		errorText = cn.callresult.text
    		cn.close()
    		end
    	end if 
    	dim rowsInserted as n 
    	'get the number of rows that were inserted
    	rowsInserted = cn.CallResult.rowsaffected
    	cn.close()
    
    
    'TIP: You can also use the sql_insert() helper function instead of using the low-level Xbasic commands
    'dim field_value_pairs as c
    'field_value_pairs = <<%txt
    'CustomerID=CustomerID
    'CompanyName=CompanyName
    'ContactName=ContactName
    'ContactTitle=ContactTitle
    '%txt%
    'dim cn as sql::connection
    'cn.open("::Name::northwind")
    'dim p as p
    'p = sql_insert(cn,"customers",field_value_pairs )
    'flagHasError = p.error
    'errorText = p.errorText 
    
    
    end function 
    
    end class
    
    
    define class REST::myRestAPI::newCustomer
        dim CustomerID as c
        dim CompanyName as c
        dim ContactName as c	
    	dim ContactTitle as c
    end class
    removed
    define class REST::myRestAPI::ContactName
    dim FirstName as c
    dim LastName as c
    end class



    Regards,

    Khanafi
    Last edited by Khanafi; 01-09-2019, 05:03 AM.

    #2
    Re: How to create REST API POST working in Alpha WAS

    Has anyone success to play with DELETE and PUT with REST API Build
    I need guide, mine doesn't working :/

    and when it is published it always ask for http://127.0.0.1:80/LivePreview/
    why on earth it always refer to LivePreview

    I am using latest build on 11 January 2019,

    5581-5237


    curl -X DELETE "http://127.0.0.1:80/LivePreview/customeInfo.a5svc/deleteUser" -H "accept: application/json" -H "content-type: application/json" -d "{ "deleteCustomer": { "CustomerID": "ZZZZZ" }}"

    Code:
    define class REST::myRestAPI
    
    
    'DELETE ----------------------------------------------------------  
    function deleteUser as c(deleteCustomer as REST::myRestAPI::deleteCustomer)
    	dim CustomerID as c = deleteCustomer.CustomerID
    	
        dim cn as sql::connection
    	dim flag as l
    	flag = cn.open("::Name::northwind")
    	if flag = .f. then
    	'there was an error
    	dim errorText as c
    	errorText = cn.callresult.text
    	end
    	end if
    	
    	'turn on portable SQL
    	cn.PortableSQLEnabled = .t.
    	dim SQL as c
    	sql = "DELETE FROM Customers WHERE CustomerID = :CustomerID"
    	dim args as sql::arguments
    	args.add("CustomerID", CustomerID)
    	
    	'execute the SQL
    	flag = cn.execute(sql,args)
    	
    	if flag = .f. then
    	'there was an error
    	
    	dim errorText as c
    	errorText = cn.callresult.text
    	cn.close()
    	end
    	end if
    	
    	dim rowsInserted as n
    	'get the number of rows that were inserted
    	rowsInserted = cn.CallResult.rowsaffected
    	cn.close()
    	
    	debug()
    	
    end function
    
    
    'UPDATE ----------------------------------------------------------  
    function updateExistingCustomer as p (updateCustomer as REST::myRestAPI::updateCustomer)
    	dim CustomerID as c = updateCustomer.CustomerID
    	dim CompanyName as c = updateCustomer.CompanyName
    	dim ContactName as c = updateCustomer.ContactName
    	dim ContactTitle as c = updateCustomer.ContactTitle
    	dim ContactTitle as c = updateCustomer.ContactTitle
    	dim Address as c = updateCustomer.Address
    	dim City as c = updateCustomer.City
    	dim Region as c = updateCustomer.Region
    	dim PostalCode as c = updateCustomer.PostalCode
    	dim Country as c = updateCustomer.Country
    	dim Phone as c = updateCustomer.Phone
    	dim Fax as c = updateCustomer.Fax
    	
        dim cn as sql::connection
    	dim flag as l
    	flag = cn.open("::Name::northwind")
    	if flag = .f. then
    	'there was an error
    	dim errorText as c
    	errorText = cn.callresult.text
    	end
    	end if
    	'turn on portable SQL
    	cn.PortableSQLEnabled = .t.
    	dim SQL as c
    	sql = "UPDATE customers SET CompanyName= :CompanyName, ContactName= :ContactName, ContactTitle= :ContactTitle, Address= :Address ,City= :City ,Region= :Region ,PostalCode= :PostalCode, Country= :Country, Phone= :Phone, Fax= :Fax WHERE CustomerID = :CustomerID"
    	dim args as sql::arguments
    	args.add("CustomerID", CustomerID)
    	args.add("CompanyName", CompanyName)
    	args.add("ContactName", ContactName)
    	args.add("ContactTitle", ContactTitle)
    	args.add("Address", Address)
    	args.add("City", City)
    	args.add("Region", Region)
    	args.add("PostalCode", PostalCode)
    	args.add("Country", Country)
    	args.add("Phone", Phone)
    	args.add("Fax", Fax)
    	
    	'execute the SQL
    	flag = cn.execute(sql,args)
    	
    	if flag = .f. then
    	'there was an error
    	
    	dim errorText as c
    	errorText = cn.callresult.text
    	cn.close()
    	end
    	end if
    	
    	dim rowsInserted as n
    	'get the number of rows that were inserted
    	rowsInserted = cn.CallResult.rowsaffected
    	cn.close()
    	
    	debug()
    end function
    
    
    
    
    
    
    
    
    'CREATE NEW USER ----------------------------------------------------------    
    function createNewCustomer as p (newCustomer as REST::myRestAPI::newCustomer)
    	dim CustomerID as c = newCustomer.CustomerID
    	dim CompanyName as c = newCustomer.CompanyName
    	dim ContactName as c = newCustomer.ContactName
    	dim ContactTitle as c = newCustomer.ContactTitle
    	dim ContactTitle as c = newCustomer.ContactTitle
    	dim Address as c = newCustomer.Address
    	dim City as c = newCustomer.City
    	dim Region as c = newCustomer.Region
    	dim PostalCode as c = newCustomer.PostalCode
    	dim Country as c = newCustomer.Country
    	dim Phone as c = newCustomer.Phone
    	dim Fax as c = newCustomer.Fax
    		
    	dim cn as sql::connection
    	dim flag as l
    	flag = cn.open("::Name::northwind")
    	if flag = .f. then
    	'there was an error
    	dim errorText as c
    	errorText = cn.callresult.text
    	end
    	end if
    	'turn on portable SQL
    	cn.PortableSQLEnabled = .t.
    	dim SQL as c
    	sql = "INSERT INTO customers(CustomerID,CompanyName,ContactName,ContactTitle,Address,City,Region,PostalCode,Country,Phone,Fax) VALUES (:CustomerID,:CompanyName,:ContactName,:ContactTitle,:Address,:City,:Region,:PostalCode,:Country,:Phone,:Fax)"
    	dim args as sql::arguments
    	args.add("CustomerID", CustomerID)
    	args.add("CompanyName", CompanyName)
    	args.add("ContactName", ContactName)
    	args.add("ContactTitle", ContactTitle)
    	args.add("Address", Address)
    	args.add("City", City)
    	args.add("Region", Region)
    	args.add("PostalCode", PostalCode)
    	args.add("Country", Country)
    	args.add("Phone", Phone)
    	args.add("Fax", Fax)
    	
    	'execute the SQL
    	flag = cn.execute(sql,args)
    	
    	if flag = .f. then
    	'there was an error
    	
    	dim errorText as c
    	errorText = cn.callresult.text
    	cn.close()
    	end
    	end if
    	
    	dim rowsInserted as n
    	'get the number of rows that were inserted
    	rowsInserted = cn.CallResult.rowsaffected
    	cn.close()
    end function
    end class
    
    define class REST::myRestAPI::newCustomer
    dim CustomerID as c
    dim CompanyName as c
    dim ContactName as c
    dim ContactTitle as c
    dim Address as c
    dim City as c
    dim Region as c
    dim PostalCode as c
    dim Country as c
    dim Phone as c
    dim Fax as c
    end class
    
    define class REST::myRestAPI::deleteCustomer
    dim CustomerID as c
    end class
    
    define class REST::myRestAPI::updateCustomer
    dim CustomerID as c
    dim CompanyName as c
    dim ContactName as c
    dim ContactTitle as c
    dim Address as c
    dim City as c
    dim Region as c
    dim PostalCode as c
    dim Country as c
    dim Phone as c
    dim Fax as c
    end class
    Last edited by Khanafi; 01-14-2019, 06:01 AM.

    Comment


      #3
      Re: How to create REST API POST working in Alpha WAS

      Demo
      https://www.screencast.com/t/wEBTrj9WWeHn

      You have to restart your WAS after Publish any changes with API Servicesm EACH TIMES!

      GET, POST, DELETE, PUT sample code
      using northwind database

      for delete I can make it work by
      1. check option has custom heading,
      2. build header
      3. set these:
      4. Header variable name: CustomerID
      5. Value: {arguments.CustomerID}



      Code:
      define class REST::myRestAPI	
      
      'GET ----------------------------------------------------------
      function getCustomer as p (customerId as c )
      	
      
      dim ops as p
      ops.connectionString = "::Name::northwind"
      dim ops.sql as c
      ops.json = .t.
      'define the nested sql queries and query properties. each level of indentation denotes a parent-child relationship
      ops.sql = <<%xstr%
      {sql: 'SELECT CUSTOMERID, COMPANYNAME, CONTACTNAME, CONTACTTITLE, CITY, COUNTRY, POSTALCODE, PHONE, FAX  FROM customers  WHERE customerid = :customerid',name: 'Top',sqlSecurityJSON: ''}
      	{sql: 'SELECT OrderID, CustomerID, EmployeeID, OrderDate FROM orders',name: 'Orders',parentKey: 'CUSTOMERID',key: 'CustomerID',sqlSecurityJSON: ''}
      		{sql: 'SELECT order_details.OrderID, order_details.ProductID, products.ProductName, order_details.UnitPrice, order_details.Quantity FROM [order details] order_details INNER JOIN products products ON  order_details.ProductID = products.ProductID',name: 'Details',parentKey: 'OrderID',key: 'order_details.OrderID',sqlSecurityJSON: ''}
      %xstr%
      dim args as sql::arguments
      args.add("customerid",customerId)
      dim p as p
      'execute the definition to get the JSON data
      p = a5_sql_nested_query_to_json_document(ops,args)
      if p.hasError = .f. then
      	dim json as c 
      	json = p.json
      	
      	getCustomer = json_parse(json)
      	
      else
      	'there was an error
      	dim errorText as c 
      	errorText = p.errortext
      	dim pout as p
      	pout.error = .t.
      	pout.errorText = errorText 
      	getCustomer = pout
      end if	
      		
      end function 
      
      
      'DELETE ----------------------------------------------------------  
      function deleteCustomer as c(CustomerID as c )
      	'dim CustomerID as c = deleteCustomer.CustomerID
          dim cn as sql::connection
      	dim flag as l
      	flag = cn.open("::Name::northwind")
      	if flag = .f. then
      	'there was an error
      	dim errorText as c
      	errorText = cn.callresult.text
      	end
      	end if
      	'turn on portable SQL
      	cn.PortableSQLEnabled = .t.
      	dim SQL as c
      	sql = "DELETE FROM customers WHERE CustomerID = :CustomerID"
      	dim args as sql::arguments
      	args.add("CustomerID", CustomerID)
      	
      	'execute the SQL
      	flag = cn.execute(sql,args)	
      end function
      
      
      'UPDATE ----------------------------------------------------------  
      function updateCustomer as p (updateCustomer as REST::myRestAPI::updatePCustomer)
      	dim CustomerID as c = updateCustomer.CustomerID
      	dim CompanyName as c = updateCustomer.CompanyName
      	dim ContactName as c = updateCustomer.ContactName
      	dim ContactTitle as c = updateCustomer.ContactTitle
      	dim ContactTitle as c = updateCustomer.ContactTitle
      	dim Address as c = updateCustomer.Address
      	dim City as c = updateCustomer.City
      	dim Region as c = updateCustomer.Region
      	dim PostalCode as c = updateCustomer.PostalCode
      	dim Country as c = updateCustomer.Country
      	dim Phone as c = updateCustomer.Phone
      	dim Fax as c = updateCustomer.Fax
      	
          dim cn as sql::connection
      	dim flag as l
      	flag = cn.open("::Name::northwind")
      	if flag = .f. then
      	'there was an error
      	dim errorText as c
      	errorText = cn.callresult.text
      	end
      	end if
      	'turn on portable SQL
      	cn.PortableSQLEnabled = .t.
      	dim SQL as c
      	sql = "UPDATE customers SET CompanyName= :CompanyName, ContactName= :ContactName, ContactTitle= :ContactTitle, Address= :Address ,City= :City ,Region= :Region ,PostalCode= :PostalCode, Country= :Country, Phone= :Phone, Fax= :Fax WHERE CustomerID = :CustomerID"
      	dim args as sql::arguments
      	args.add("CustomerID", CustomerID)
      	args.add("CompanyName", CompanyName)
      	args.add("ContactName", ContactName)
      	args.add("ContactTitle", ContactTitle)
      	args.add("Address", Address)
      	args.add("City", City)
      	args.add("Region", Region)
      	args.add("PostalCode", PostalCode)
      	args.add("Country", Country)
      	args.add("Phone", Phone)
      	args.add("Fax", Fax)
      	
      	'execute the SQL
      	flag = cn.execute(sql,args)
      	
      	if flag = .f. then
      	'there was an error
      	
      	dim errorText as c
      	errorText = cn.callresult.text
      	cn.close()
      	end
      	end if
      	
      	dim rowsInserted as n
      	'get the number of rows that were inserted
      	rowsInserted = cn.CallResult.rowsaffected
      	cn.close()
      	
      end function
      
      
      'CREATE ----------------------------------------------------------    
      function createCustomer as p (newCustomer as REST::myRestAPI::newPCustomer)
      	dim CustomerID as c = newCustomer.CustomerID
      	dim CompanyName as c = newCustomer.CompanyName
      	dim ContactName as c = newCustomer.ContactName
      	dim ContactTitle as c = newCustomer.ContactTitle
      	dim ContactTitle as c = newCustomer.ContactTitle
      	dim Address as c = newCustomer.Address
      	dim City as c = newCustomer.City
      	dim Region as c = newCustomer.Region
      	dim PostalCode as c = newCustomer.PostalCode
      	dim Country as c = newCustomer.Country
      	dim Phone as c = newCustomer.Phone
      	dim Fax as c = newCustomer.Fax
      		
      	dim cn as sql::connection
      	dim flag as l
      	flag = cn.open("::Name::northwind")
      	if flag = .f. then
      		
      	'there was an error
      	dim errorText as c
      	errorText = cn.callresult.text
      	cn.close()
      	end
      	end if
      	
      	'turn on portable SQL
      	cn.PortableSQLEnabled = .t.
      	dim SQL as c
      	sql = "INSERT INTO customers(CustomerID,CompanyName,ContactName,ContactTitle,Address,City,Region,PostalCode,Country,Phone,Fax) VALUES (:CustomerID,:CompanyName,:ContactName,:ContactTitle,:Address,:City,:Region,:PostalCode,:Country,:Phone,:Fax)"
      	dim args as sql::arguments
      	args.add("CustomerID", CustomerID)
      	args.add("CompanyName", CompanyName)
      	args.add("ContactName", ContactName)
      	args.add("ContactTitle", ContactTitle)
      	args.add("Address", Address)
      	args.add("City", City)
      	args.add("Region", Region)
      	args.add("PostalCode", PostalCode)
      	args.add("Country", Country)
      	args.add("Phone", Phone)
      	args.add("Fax", Fax)
      	
      	'execute the SQL
      	flag = cn.execute(sql,args)
      	
      	if flag = .f. then
      	'there was an error
      	
      	dim errorText as c
      	errorText = cn.callresult.text
      	cn.close()
      	end
      	end if
      	
      	dim rowsInserted as n
      	'get the number of rows that were inserted
      	rowsInserted = cn.CallResult.rowsaffected
      	
      end function
      
      end class
      
      'CLASS ---------------------------------------------------------- 
      
      define class REST::myRestAPI::newPCustomer
      dim CustomerID as c
      dim CompanyName as c
      dim ContactName as c
      dim ContactTitle as c
      dim Address as c
      dim City as c
      dim Region as c
      dim PostalCode as c
      dim Country as c
      dim Phone as c
      dim Fax as c
      end class
      
      define class REST::myRestAPI::updatePCustomer
      dim CustomerID as c
      dim CompanyName as c
      dim ContactName as c
      dim ContactTitle as c
      dim Address as c
      dim City as c
      dim Region as c
      dim PostalCode as c
      dim Country as c
      dim Phone as c
      dim Fax as c
      end class
      NB:
      How to edit my old post instead create new one reply in the forum?

      Comment

      Working...
      X