Share My Creation [Project Template] [Web] API Server

swamisantosh

Member
Licensed User
Longtime User
We would be thankful , if you can keep share future development Web API Template . just for purpose of learning only
 

peacemaker

Expert
Licensed User
Longtime User
Mobile operators are often blocking many ports. And only 80 or 443 (HTTPS) are for sure available.
So, is it OK for such applications ?
 

aeric

Expert
Licensed User
Longtime User
Mobile operators are often blocking many ports. And only 80 or 443 (HTTPS) are for sure available.
So, is it OK for such applications ?
I don't have problem with my (VPS) hosting. My apps are able to connect to it.
If any hosting provider block your ports then you may need to contact them to open the ports for you.
Not sure about Mobile operators. My mobile ISP doesn't block.
 

peacemaker

Expert
Licensed User
Longtime User

Not hosting. Mobile operators of users who try to use the server from their mobile phones (clients), but the port like 59000 is locked. And cannot be unlocked for sure.
 

aeric

Expert
Licensed User
Longtime User
Not hosting. Mobile operators of users who try to use the server from their mobile phones (clients), but the port like 59000 is locked. And cannot be unlocked for sure.
Not sure about the ISP in your country. As long as the port number doesn't exceed 65,535 I think it should be fine. If we use smaller port number, it is likely would conflict with some reserved ports. If I am hosting multiple apps on the same server, then it is not ideal to only host the apps on the same ports (80 and 443). If this is the case then I think you have no choice but to use different domain or create subdomain. I am not expert on this topic and this is what I understand.
 

peacemaker

Expert
Licensed User
Longtime User
to use different domain or create subdomain

Ah, clear, so, for 80 port we have to host the app on separate subdomain to solve the trouble with mobile operator ports.
Clear, thanks.
 

aeric

Expert
Licensed User
Longtime User
Ah, clear, so, for 80 port we have to host the app on separate subdomain to solve the trouble with mobile operator ports.
Clear, thanks.
I think so. If you are hosting B4J server apps, I guess you have full control on the port numbers of the firewall. In my case, my VPS is running on Ubuntu Linux and I can open all ports. This is similar on Windows server where you can control which ports to allowed or which IP addresses to whitelist. Unless this settings are blocked by the hosting provider by default. On the Mobile operator side, you may need to find out. If ports 80 and 443 are the only allowed port numbers, then I guess using different subdomain may solve the issue for hosting multiple apps.
 

Roberto P.

Well-Known Member
Licensed User
Longtime User
HI Aeric,
thank for your work.

awesome template and starting point for API development with B4J.

I believe this needs to be natively enhanced and integrated into B4J. We have now entered the era of APIs and the Native Cloud.

Why use Node.js or Spring Boot when we have B4J available which is simpler, lighter and has a lot of libraries?

Regards
 

aeric

Expert
Licensed User
Longtime User
I didn't understand
I suppose I have provided sufficient information about this project (or am I posting too much that anyone would not interested to read further) in the first post.
The history or background of how this project was born is from the following post:
[Wish] B4J as a Powerful Web API Development Tool

Actually, I never thought to create it myself.
btw, where can i download your API template above?
I have no idea. I am not sure I will create it.

But then I created it.
Note that anyone can create new project templates.

I consider this project as a "proof of concept". However, if I continue to update it, one day it might become a tool for building app aiming for production. I have seen something like Django and Yii framework to quickly scaffold a project.

Now, my question is:
Do you think I should create a client app (using B4A, B4i or B4J and even html+ajax or other languages such as PHP, ASP.NET, VB.NET) to consume the API of this template? (to further explain what this template could be use for)
 

aeric

Expert
Licensed User
Longtime User
A simple example of consuming the API would be AWESOME! GREAT JOB ON THIS TEMPLATE!!
I just uploaded a sample html page (ajax-test.zip) in the first post. By the way, if you have created a project with this template, the search function at the bottom also demonstrate how to consume the API using AJAX. I will create some B4X client apps if I am free later.
 

aeric

Expert
Licensed User
Longtime User
I just uploaded a sample html page (ajax-test.zip) in the first post.
I created this html test for checking the CORS filter I added in version 1.08.

To test CORS is working or not, restrict the B4J Web API app with the following (line #108):
B4X:
ConfigureCORS(ROOT_PATH & "category/*", "http://127.0.0.1:19800", "", "") ' test.html

Then edit the url in html file:
HTML:
<!DOCTYPE html>
<html>
<head>
    <title>CORS TEST</title>
    <script type="text/javascript" src="jquery.min.js">
    </script>
</head>
<body>
    <div>
        <p class="id">ID: </p>
        <p class="name">Name: </p>
        <div id="data"></div>
    </div>
</body>
</html>
<script type="text/javascript">
    $(document).ready(function()
    {
        $.ajax(
        {
            url: "http://127.0.0.1:19800/v1/category/2/product/"
        }).then(function(data, status, jqxhr)
        {
            $('.id').append(data.r[0].id);
            $('.name').append(data.r[0].product_name);
            $.each(data.r, function()
            {
                $('#data').append('<p>');
                $.each(this, function(key, value)
                {
                    $('#data').append(key +': '+ value+'<br>');
                });
                $('#data').append('</p>');
            });
            console.log(jqxhr);
        });
    });
</script>

Try open the HTML locally (just double-click), put it inside Laragon (or XAMP server) running on different port number or upload to your hosting.
Right-click the browser and Inspect (Ctrl+Shift+I). Click Console tab, you will see:
Access to XMLHttpRequest at 'http://127.0.0.1:19800/v1/category/2/product/' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Failed to load resource: net::ERR_FAILED

p/s: I am not expert on this topic. I guess I am doing it correctly.
 

yaqoob

Active Member
Licensed User
Longtime User
Hi aeric,

Thank you for share your creation. I am getting the error ("Utility - 31: Unknown type: json<br />Are you missing a library reference?" see file error1. Even though the library Json is selected and B4J is the latest version (9.10) see file error2. I noticed you are using JSON 1.2, but what is available as the internal library is 1.10. I did what you suggested in post 4 to update the JSON library, but still, I am getting the same error.

Any suggestions?
 

Attachments

  • error2.png
    243.2 KB · Views: 220
  • error1.jpg
    449.8 KB · Views: 219
Last edited:

aeric

Expert
Licensed User
Longtime User
You need the latest version of JSON library (version 1.20)
 

yaqoob

Active Member
Licensed User
Longtime User
Thank you for your feedback. It is working now. The mistake I have done copied the JSON library file to the additional library. Once I moved them to B4J internal library it worked
 

luke2012

Well-Known Member
Licensed User
Longtime User
WOW. Outstanding work
This is a REST API Server implementation ?
This web api could be called by Angular apps using REST API Client ?
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…