This topic is locked
[SOLVED]

 Creating APIs for use by other apps - 3 Scenarios

7/3/2020 9:41:32 AM
ASPRunner.NET General questions
FrankR_ENTA author

I have been using ASPRunner.NET 10.4 to generate APIs that will be used by other applications in our business. ASPRunner.NET has allowed me to be extremely productive with this work. What can take many months using more code intensive manual approaches is handled by ASPRunner.NET in a very Low Code fashion.
I encountered 3 scenarios over the past week, and I received stellar support from Xlinesoft on these 3 scenarios. I want to pay some of that forward by documenting those scenarios here. It will hopefully save some of you some time down the road.
All of these scenarios use the incredible SQL View support for generating a service method. For these illustrations, we will use a Products table with this data:



ProductId Name

1 ProductA1

2 ProductA2

3 ProductA3

4 ProductA4

5 ProductB1

6 ProductB2

9 Other

12 Misc


I will put each of the 3 scenarios in a separate post.

FrankR_ENTA author 7/3/2020

Scenario 1: Service method that needs to return a list of results sorted.


SQL View Definition:

SELECT

ProductId,

Name As ProductName

FROM Products

ORDER BY Name


If you run that query interactively, it will indeed sort by Name. The result through the API with this invocation was not sorted:

http://localhost:8087/api/v1?table=testsort&action=list


This one simply required an update. The latest build and REST support now allows for the result through the API to be returned sorted as per the query.
Excellent.

FrankR_ENTA author 7/3/2020

Scenario 2: Service method with both a filter parameter and an OR statement for selection of records.
SQL View Definition:

SELECT

ProductId,

Name As ProductName

FROM Products

WHERE Name like '%:{filter.ProductName}%'

OR Name like '%Other%'

OR Name like '%Misc%'


If you run that query interactively, it will include both the records that match by the filter parameter, as well as the records included with the OR. When invoked through the API, the result list was missing the OR records - Other and Misc.

http://localhost:8087/api/v1?table=testparmandor&action=list&q=(ProductName~contains~ProductA)


The solution for this one is to click the Generate C# code button from the SQL View screen and comment out this snippet:



// filter results, apply search, security & other filters

// Commented out, per direction of Xlinesoft - FR, 7/2020

//result = dataSource.filterResult( result, command.filter )


With that in place, the invocation through the API includes the OR records Other and Misc.

jadachDevClub member 7/3/2020

Thanks for sharing.

FrankR_ENTA author 7/3/2020

Scenario 3: Service method with two filter parameters with an OR.
SQL View Definition:

SELECT

ProductId,

Name As ProductName,

Name As FirstProductParm,

Name As SecondProductParm

FROM Products

WHERE Name LIKE '%:{filter.FirstProductParm}%' OR Name LIKE '%:{filter.SecondProductParm}%'


If you run that query interactively, with the first filter as 'ProductA' and the second filter as 'Other', it will include both the ProductA records as well as the Other record. When invoked through the API, it did not return any records.

http://localhost:8087/api/v1?table=testtwoparms&action=list&q=(FirstProductParm~contains~ProductA)(SecondProductParm~contains~other)


The solution for this one - is the same as the solution for Scenario 2. Click the Generate C# code button from the SQL View screen and comment out this snippet:



// filter results, apply search, security & other filters

// Commented out, per direction of Xlinesoft - FR, 7/2020

//result = dataSource.filterResult( result, command.filter )


With that in place, the invocation through the API includes both the ProductA records as well as the Other record.
Excellent.