Skip to content

pyhoon/webapi-2-b4j

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

webapi-2-b4j

Version: 2.07

Create Web API Server using B4X project template

Preview

Web API Template

If you don't want to connect to any SQL database, see MinimaList API Server

For older version webapi-b4j, please check https://github.com/pyhoon/webapi-b4j


Template:

  • Web API Server (2.07).b4xtemplate

Depends on:

Features:

  • ApiHandler and WebHandler are used for routing to Controller classes
  • HelpHandler (optional)
  • API documentation is generated automatically. You don't need external tools (e.g Postman or Swagger) for testing.
  • Access tokens can be embeded into request header in HelpHandler.
  • Controller classes are added to a list in Main module to show in the documentation.
  • Configuration
    • Web and API paths
    • Versioning
    • Simple JSON Response (Map or List)
    • Session
    • Cookies
    • Welcome message
  • Endpoint
    • Endpoint name is based on controller's name by default e.g ProductsController produces /web/api/v2/products
    • Endpoint name can be overridden by using #Name tag e.g /web/api/v2/product
    • Custom version name using #Version tag e.g v2, live, demo, dev, staging
    • Description in documentation is set using #Desc tag (in Web API v1, it was set by #Desc1, #Desc2 or Literals that was very confusing)
    • API endpoint can be hidden using #Hide tag
  • Clients

Code Example

Private Sub GetCategory (id As Long)
    ' #Version = v2
    ' #Desc = Read one Category by id
    ' #Elements = [":id"]

    DB.Table = "tbl_category"
    DB.Find(id)
    If DB.Found Then
        HRM.ResponseCode = 200
        HRM.ResponseObject = DB.First
    Else
        HRM.ResponseCode = 404
        HRM.ResponseError = "Category not found"
    End If
    DB.Close
    ReturnApiResponse
End Sub

Support this project