B4J Library [Web] WebApiUtils v4

Attachments

  • WebApiUtils.b4xlib
    10.8 KB · Views: 35
Last edited:

aeric

Expert
Licensed User
Longtime User
Changes:
  • SimpleResponse removed
  • VerboseMode as new property, when value is True, the response json returns array or object (formerly only array)
  • Updated Code Snippets
Migration:
  1. VerboseMode is opposite of SimpleResponse.Enable (version 3)
    B4X:
    Private Sub Configurable
        conf.EnableHelp = True
        conf.EnableSSL = True
        conf.EnableCORS = True
        conf.VerboseMode = True
        conf.StaticFilesBrowsable = False
    End Sub
  2. To initialize API Handler
    B4X:
    Public Sub Initialize
        HRM.Initialize
        HRM.VerboseMode = Main.conf.VerboseMode
    End Sub
 
Last edited:

aeric

Expert
Licensed User
Longtime User
Version: 4.10

What's New
  • XML format API is finally available
  • ReturnHttpResponse2 (Private)
  • Custom root (default is <content>) and result element (default is <result>)
To generate XML format API, initialize the handler like following:
B4X:
Public Sub Initialize
    HRM.Initialize
    HRM.VerboseMode = Main.conf.VerboseMode
    HRM.ContentType = WebApiUtils.CONTENT_TYPE_XML
End Sub
Note: Verbose mode works for both JSON and XML.
 

aeric

Expert
Licensed User
Longtime User
Version: 4.30

What's New
  • Too much addition +1224 and deletion -480
  • Many code are still under experimental
  • This is a preparation to enable Web API Server v4 to generate JSON and XML format API with ordered keys structure (for viewing purpose)
  • This also will promise more flexible custom keys for JSON verbose mode instead of using the meaningless a-r-s-e-m keys
So whether you are feeling s-e-r-a-m to "pakai" the new Web API Server v4 or is it really feel m-e-s-r-a to you,
you may able to customize the keys as you like and become the s-m-a-r-t , m-a-s-t-e-r or s-t-a-r !
You are no longer limited to get the a-r-s-e-m format in Web API Server v3.
You can even change the keys with combination of "status", "code", "message", "error", "type", "results" or part of them.

This is the most important feature for the upcoming Web API Server v4 using WebApiUtils v4.
Don't forget MiniORMUtils library is getting more powerful and flexible, which has enabled this to happen !

old version
VS
version 4


Footnote:
In Malaysian language,
seram means scary
mesra means friendly
pakai means wear or use. Web API Server may renamed to Pakai framework in the future.

Note: All the words mentioned above can be formed from the combination of alphabets from the RESPONSE_ELEMENT constants that represent the properties of verbose mode.
You can find the following code on top of WebApiUtils.bas file. Have FUN!
B4X:
' Web API Utility
' Version 4.30
Sub Process_Globals
    Public Const CONTENT_TYPE_HTML As String = "text/html"
    Public Const CONTENT_TYPE_JSON As String = "application/json"
    Public Const CONTENT_TYPE_XML As String = "application/xml"
    Public Const CONTENT_TYPE_PDF As String = "application/pdf"
    Public Const CONTENT_TYPE_PNG As String = "image/png"
    Public Const RESPONSE_ELEMENT_MESSAGE As String  = "m"
    Public Const RESPONSE_ELEMENT_CODE As String     = "a"
    Public Const RESPONSE_ELEMENT_STATUS As String   = "s"
    Public Const RESPONSE_ELEMENT_TYPE As String     = "t"
    Public Const RESPONSE_ELEMENT_ERROR As String    = "e"
    Public Const RESPONSE_ELEMENT_RESULT As String   = "r"
    Type HttpResponseContent (ResponseBody As String)
    Type HttpResponseMessage (ResponseMessage As String, ResponseCode As Int, ResponseStatus As String, ResponseType As String, ResponseError As Object, ResponseData As List, ResponseObject As Map, ResponseBody As Object, ContentType As String, XmlRoot As String, VerboseMode As Boolean, OrderedKeys As Boolean, ResponseKeys As List, KeysAlias As List)
End Sub
 
Last edited:

aeric

Expert
Licensed User
Longtime User
Version: 4.40

What's New
  • RequestDataText sub added
  • ReturnHttpResponse sub updated
  • KeysAlias property renamed to ResponseKeysAlias
  • Identation parameter spelling corrected to Indentation
 

aeric

Expert
Licensed User
Longtime User
Version: 4.50

What's New
  • Updated HttpResponseMessage type
    • added XmlElement property
    • added PayloadType property
  • Updated ReturnHttpResponse sub
    • fix XML support
    • many other bug fixes
  • Updated ProcessOrderedJsonFromMap sub
  • Updated ProcessOrderedXmlFromList sub
  • Added ParseXML sub
  • Added EscapeHtml sub
  • Added ValidateContent sub
  • Fix Main.conf.ServerUrl in Web Handler.txt Snippet
 
Top