Share My Creation [Project Template] Web API Server 3

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

1732693100910.png


Template:
  • Web API Server (3.10).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: 78
  • WebApiUtils.b4xlib
    8.8 KB · Views: 52
  • Web API Server (3.10).b4xtemplate
    434.5 KB · Views: 25
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.
 

aeric

Expert
Licensed User
Longtime User
Updates:
08/11/2024
  • Template:
    • Web API Server (3.10 beta 1).b4xtemplate
What's New:
  • Fix error in Main module (line #129) when selecting MySQL
  • New ServerUrl in ServerConfigurations type
  • ConfigurePort sub replaces ConfigureSSL
  • Remove ApplySettings sub
  • Updated HelpHandler
    • New VerbSection type to simplify some methods signature
    • GenerateVerbSection now accepting a single Verbsection type
    • GenerateDocItem now accept a single Map
    • GenerateLink sub updated using ServerUrl
    • GenerateNoApiLink sub added for adding non api handler to documentation
    • ReadHandlers sub updated
    • JavaScript updated
      • fade-out and fade-in animation on bootstrap alert when submitting the endpoint again
      • html elements using id instead of button id
      • Some code for basic and token authentication support
  • Next update will try to update html for release
Note: This is the first beta for v3.10 and it is expecting to contains some bugs.
 

aeric

Expert
Licensed User
Longtime User
Updates:
10/11/2024
  • Template:
    • Web API Server (3.10).b4xtemplate
What's New:
  • Fix error in Main module (line #129) when selecting MySQL
  • New ServerUrl in ServerConfigurations type
  • ConfigurePort sub replaces ConfigureSSL
  • Remove ApplySettings sub
  • Updated HelpHandler
    • New VerbSection type to simplify some methods signature
    • GenerateVerbSection now accepting a single Verbsection type
    • GenerateDocItem now accept a single Map
    • GenerateLink sub updated using ServerUrl
    • GenerateNoApiLink sub added for adding non api handler to documentation
    • ReadHandlers sub updated
    • JavaScript updated
      • fade-out and fade-in animation on bootstrap alert when submitting the endpoint again
      • html elements using id instead of button id
      • Some code for basic and token authentication support
      • Standardize coding format (removed ending semicolons and replaced single quote with double quotes)
  • help.html loads server url based on config.ini during production
Note: If you want to show help during Production, make sure run project in Debug mode at least once to generate help.html in Objects folder. Delete the old help.html and regenerate again if you have made new changes to the APIs. It is not recommend to enable the help page and expose it to public without protecting it.
 
Last edited:
Top