B4J Question Can I write an API in B4J?

Pravee7094

Active Member
Hi all,
I wrote an API for mobile application (developed by B4A) using Slim Framework (PHP).

API model Example :
PHP:
    $app->get('/filname/getallusers', function (Request $request, Response $response)
    {
        $db = $this->get(PDO::class);
        $sql = "SELECT username FROM talbename";
        $exec_sql = $db->prepare($sql);
        $exec_sql->execute();

        $data = $exec_sql->fetchAll(PDO::FETCH_ASSOC);
        $data_encode = json_encode($data);
        $response->getBody()->write($data_encode);
        return $response->withHeader('Content-Type', 'application/json');
    });

This code is used to Get the users username from the table.
Can I write an API in B4J like the API model example?

I tried B4J with my B4A application. I learned JRDC2 Remote connection database. But in the JRDC2, I can run only one query in config.properties.
But I have to write the one function for one operation like above example API coding.

Can I do that with B4J?

Any suggestion or Reference?

Thanks
 

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
Hi! Yes you can. JRDC2 is just a commodity to be used with other b4x products.

You can create what you need with Jserver, this is actually an http server where you can create endpoints. Jrdc2 is based on this one.

Just search for webapps on the forum.

By the way, if you are still communicating with b4a and b4i its better to use the b4xserializator class (from the randomAccessFile library) if you are going for other platforms you can use json.
 
Upvote 0

Harris

Expert
Licensed User
Longtime User
Hi! Yes you can. JRDC2 is just a commodity to be used with other b4x products.

You can create what you need with Jserver, this is actually an http server where you can create endpoints. Jrdc2 is based on this one.

Just search for webapps on the forum.

By the way, if you are still communicating with b4a and b4i its better to use the b4xserializator class (from the randomAccessFile library) if you are going for other platforms you can use json.
YOU are one smart dude... amazing.
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
see samples (API REST):

B4J:

PHP:

Note:
In the personal case, I prefer PHP REST API, using Slim Framework for our data services project for mobile applications.
 
Upvote 0

avalle

Active Member
Licensed User
Longtime User
I wrote a fairly complex REST API project in B4J using jServer and SQLite. The very good thing of this approach is that working with jServer is very easy as you can define Handler classes to manage your API paths. And unless you have crazy performance or volume requirements, SQLite does an excellent job for the DB and it's also easy to use with B4J
 
Upvote 0
Top