Share My Creation [Project Template] Web API Server 3

Version: 3.00
Description: Create Web API Server using B4X
Database: MySQL, SQLite



Template:
  • Web API Server (3.00).b4xtemplate
Depends on:
  • WebApiUtils.b4xlib (v3.02)
  • MiniORMUtils.b4xlib (v1.14)
  • sqlite-jdbc-3.39.3.0.jar (or your preferred version)
  • mysql-connector-java-8.0.30.jar (or your preferred version)
Please check this tutorial for guides.

Reminder: Please do not post any question on this thread.

Always remember to start a new thread for any question and tag "Web API Server 3".

You may also ask in the [Q&A] thread.
 

Attachments

  • MiniORMUtils.b4xlib
    14.4 KB · Views: 37
  • WebApiUtils.b4xlib
    8.8 KB · Views: 12
  • Web API Server (3.00).b4xtemplate
    434 KB · Views: 12
Last edited:

aeric

Expert
Licensed User
Longtime User
Updates:
29/10/2024
  • Template:
    • Web API Server (3.00beta4).b4xtemplate *updated
  • Depends on:
    • WebApiUtils.b4xlib (v3.01) *updated
    • MiniORMUtils.b4xlib (v1.14)
    • sqlite-jdbc-3.39.3.0.jar (or your preferred version)
    • mysql-connector-java-8.0.30.jar (or your preferred version)
Introduction of :
1. ElementMatch (Pattern As String) As Boolean
2. CropElements (FullElements() As String, StartingElementIndex As Int) As String() -> (WebApiUtils.b4xlib)

With these new methods, I am trying to simplify the way writing APIs which I think make more sense to newbie of this Web API framework.

Example:
B4X:
Sub Handle (req As ServletRequest, resp As ServletResponse)
    Request = req
    Response = resp
    Method = Request.Method.ToUpperCase
    Dim FullElements() As String = WebApiUtils.GetUriElements(Request.RequestURI)
    Elements = WebApiUtils.CropElements(FullElements, 3) ' 3 For Api handler
    Select Method
        Case "GET"
            If ElementMatch("") Then ' /api/categories
                GetCategories
                Return
            End If
            If ElementMatch("id") Then ' /api/categories/1
                GetCategoryById(ElementId)
                Return
            End If
        Case "POST"
            If ElementMatch("") Then ' /api/categories
                PostCategory
                Return
            End If  
        Case Else
            Log("Unsupported method: " & Method)
            ReturnMethodNotAllow
            Return
    End Select
    ReturnBadRequest
End Sub

Instructions: Download the updated template and library files in 1st post.
 

aeric

Expert
Licensed User
Longtime User
Updates:
30/10/2024

Template:
  • Web API Server (3.00rc1).b4xtemplate *updated
Depends on:
  • WebApiUtils.b4xlib (v3.02) *updated
    • MiniORMUtils.b4xlib (v1.14)
    • sqlite-jdbc-3.39.3.0.jar (or your preferred version)
    • mysql-connector-java-8.0.30.jar (or your preferred version)
What's New:
- Fix issue with SSL settings in Release
- Fix issue in FindApiHandler to check missing keywords key in request body
- Updated new Code Snippets to WebApiUtils for creating new Web and Api handlers

Instructions: Download the updated template and library files in 1st post.
 

aeric

Expert
Licensed User
Longtime User
Releases:
Template:
  • Web API Server (3.00).b4xtemplate *updated
Depends on:
  • WebApiUtils.b4xlib (v3.02)
  • MiniORMUtils.b4xlib (v1.14)
  • sqlite-jdbc-3.39.3.0.jar (or your preferred version)
  • mysql-connector-java-8.0.30.jar (or your preferred version)
What's New:
- Fix issue with SSL settings in Release
- Fix issue in FindApiHandler to check missing keywords key in request body
- Updated new Code Snippets to WebApiUtils for creating new Web and Api handlers
- Renamed JavaScripts files name and move from js to scripts folder inside www/assets

Instructions: Download the updated template and library files in 1st post.
Please remember to clear browser cache due to changes in JavaScript files.
 
Last edited:

aeric

Expert
Licensed User
Longtime User
Hi guys,
I have uploaded the wrong template file.
I was using RAR format in WinRAR. It will not work.
It is now fixed using ZIP format.

Please download the template again.

Sorry for any inconvenience.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…