Friday, April 17, 2020

5 Schritte zur COVID-19 Web-App (APEX REST Services)




In diesem Blog möchten wir zeigen wie einfach es ist eine APEX App zu erstellen, die anhand von REST Services Daten aus dem Web ausliest. Passend zur aktuellen Situation (COVID-19) erstellen wir eine Beispiel Anwendung, die uns tagesaktuelle Daten anzeigt. Hierzu benötigen wir gerade mal 5 Arbeitsschritte!


  • Neue APEX-App erstellen
  • Web-Source´s hinzufügen
  • Classic Report hinzufügen
  • List-of-Value erstellen
  • Filter hinzufügen



1. Neue APEX-App

Als erstes erstellen wir eine neue Anwendung in APEX. Hierzu als Workspace-Administrator einloggen und unter Create Application eine neue App erstellen.




2. Web-Source´s hinzufügen

Als Nächstes werden wir die benötigten Web-Sources anlegen. In unserem Beispiel beziehen wir uns auf die API´s von COVID-19. Welche unter anderem zur Verfügung stehen und eine passenden Dokumentation findet Ihr unter folgenden Link: https://covid19api.com/


Wir wollen in unserer Anwendung die Fallzahlen je Land auswerten. Dafür benötigen wir 2 Web-Sources.


  1. GET COUNTRIES: https://api.covid19api.com/countries
  2. GET SUMMARY: https://api.covid19api.com/summary

Die API "SUMMARY" liefert uns die aktuellen Zahlen. "COUNTRIES" liefert uns Länderdaten.

Um die API`s in APEX einbinden zu können müssen wir nun unter "Shared Components > Web Source Modules" neue Web-Sources erstellen. Hierzu auf Create klicken und im nächsten Schritt "From Scratch" auswählen. 

Dann folgende Einträge eingeben:

  • Web Source Type: Simple HTTP
  • Name: COVID19 SUMMARY
  • URL Endpoint: https://api.covid19api.com/summary




Anschließend Next klicken und den nächsten Schritt ebenfalls mit Next bestätigen.
Da wir für diese API keine Authentication benötigen können wir den darauffolgenden Schritt direkt wieder mit Discover überspringen. Zuletzt wird noch eine Vorschau angezeigt, die wir dann mit Create Web Source final abschließen können.

Das gleiche machen wir anschließend noch mit unserer zweiten API "COUNTRIES".

Hier dann folgende Einträge eingeben:


  • Web Source Type: Simple HTTP
  • Name: COVID19 COUNTRIES
  • URL Endpoint: https://api.covid19api.com/countries

Und alles weitere wie zuvor durchklicken.

Nun ist unser zweiter Schritt erledigt und wir haben die API´s in unserer APEX App eingebunden, so dass wir im nöchsten Schritt darauf zugreifen können.


3. Classic Report erstellen

Jetzt wollen wir die Daten aus den zuvor angelegten Web-Sources in Form von einem Classic Report anzeiegn lassen. Hierzu gehen wir zur Page 1 und fügen dieser einen Classic Report hinzu.

Unter Source wählen wir die Location "Web Source" und Module "COVID19 SUMMARY".




Jetzt können wir bereits die Anwendung ausführen und sehen einen Report mit den Daten aus der COVID-19 API. Als Filtermöglichkeit wollen wir aber noch eine Auswahlliste der Länder zur Verfügung stellen. Hierzu benötigen wir zunächst eine List-of-Value.


4. List-of-Value "Countries" erstellen

Wechselt wieder zu den Shared Components und erstellt unter "List of Values" eine neue LOV mit der Option "From scratch". Diese nennen wir "Countries" und wählen den Type "Dynamic" aus. Im nächsten Schritt wählen wir dann als Data Source "Web Source" und nehmen als Module unsere zuvor angelegte Web Source "COVID19 COUNTIRES".




Als Return Value wählen wir "ISO2" und Display Value "COUNTRY" und klicken dann zum erstellen Create. Jetzt haben wir die LOV erstellt und können im letzten Schritt noch die Select-Liste zur Auswahl eines Landes hinzufügen.


5. Filter hinzufügen

Zuletzt wollen wir für den Classic Report noch einen Filter hinzufügen, worüber wir nach einem Land auswerten können. Hierzu eine "Select-List" auf der Seite 1 hinzufügen. Unter List of Values den Type "Shared Components" und die zuvor erstellte LOV "Countries" auswählen. 




Damit die Auswahl den Report filtert benötigen wir jetzt noch eine Where-Clause
Hierzu unter Local Post Processing folgende Where Clause eintragen: 

COUNTRYCODE = :P1_COUNTRY
or :P1_COUNTRY is null


Zuletzt noch unter Settings bei Page Actions on Selection "Submit Page" auswählen, damit der Report nach einer Auswahl automatisch aktualisiert wird.


Fertig ist unsere COVID-19 App in nur 5 Arbeitsschritten :-)


Hier geht es zur Demo-App: COVID-19 Demo

Labels: , ,

9 Comments:

At April 20, 2020 at 9:10 PM , Blogger Mohammad Mazharuddin said...

Hi dears,
I am facing the following issue while working on this exercise:

ORA-20001: You have exceeded the maximum number of web service requests per workspace. Please contact your administrator.

How to fix this ?

Actually, you have missed to apply the "Where Clause" in the classic report for the country selected from the LOV in the "select list" to take effect. Possibly I exceeded some limit of web service requests in order to debug the issue.

So what is the resolution now to access the web services from the ttps://api.covid19api.com

 
At April 20, 2020 at 9:42 PM , Blogger Mohammad Mazharuddin said...

I guess, the resolution is to add a type "Where/Order By Clause" in the classic report property  "Local Post Processing" and then add the Where Clause "COUNTRY = :P1_COUNTRY_LIST (the select list item name)". Could you please provide me your feedback.

I am depending on you feedback because the web services from the https://api.covid19api.com is no longer accessible now from my https://apex.oracle.com/ login

 
At April 21, 2020 at 8:36 AM , Blogger Timo said...

Hi, thanks for the hint...i forgot the where-clause in my blog but Mohammad Mazharuddin is right...we have to add the where clause in the property "Local Post Processing"...i updated the blog :-)

Please try to cache the Web Source responses to avoid making a request for each page load. Click on the GET operation in order to see the details for this operation; then look up the Caching tab.

 
At April 21, 2020 at 11:57 AM , Blogger Mohammad Mazharuddin said...

So nice of you for your great deeds and the prompt response to me. I am eagerly waiting to be able to put this to practice. Thanks a lot. Keep up the good work!

I had also written yesterday to the Oracle APEX support for the redressal of my "ORA-20001: You have exceeded the maximum number of web service requests per workspace..." problem. I am waiting for their response as the problem is not fixed yet. I also read somewhere in forums that it would be fixed within 24 hours by itself... I am waiting ...

I am also looking forward to apply your hint "Please try to cache the Web Source responses to avoid making a request for each page load...". It would be a good idea if you could elaborate more by way of a blob article when possible for you. Thanks

 
At April 21, 2020 at 12:40 PM , Blogger Mohammad Mazharuddin said...

"blog", not "blob": - ) . Sorry for the typo.

 
At April 22, 2020 at 10:25 AM , Blogger Mohamad Bouchi said...

Hi Mohammad,

I would like to draw your attention, that there is a maximum requests you can do. I don't know the maximum number if you are using the oracle instance. But if you are working on a local instance then it would be 1000 request per day, nevertheless this number can be edited by a workspace admin.

 
At April 22, 2020 at 4:21 PM , Blogger Mohammad Mazharuddin said...

This comment has been removed by the author.

 
At April 22, 2020 at 4:23 PM , Blogger Mohammad Mazharuddin said...

Hello Mohamad Bouchi, yes true. Actually the "maximum requests" is configured much much less (than the default 1000) in the Oracle APEX https://apex.oracle.com/ instance; hence the problem I had faced which was resolved automatically after 24 hours as I had expected.

Actually I was looking forward to apply the hint provided by Timo about the "Caching" to work-around this problematic issue. I am replying his comment now. You also kindly have a look at it.

Thanks,
Mohammad Mazharuddin

 
At April 22, 2020 at 4:28 PM , Blogger Mohammad Mazharuddin said...

Hello Timo, I just looked at how to apply the hint you provided about the "Caching" of the Web Source Modules. I notice the default value selected in the "Caching" property of both the Web Source Modules "COVID19 COUNTRIES" and "COVID19 SUMMARY" is the first one, "Disabled". The other three values available in the list are as follows:

For All Users
By User
By Session

I have no idea yet which of the options will be the best one in order to avoid the problem of "ORA-20001: You have exceeded the maximum number of web service requests per workspace...", I faced yesterday.

Thanks,
Mohammad Mazharuddin

 

Post a Comment

Note: Only a member of this blog may post a comment.

Subscribe to Post Comments [Atom]

<< Home