B4J Library [Web] MinimaList Controller

Version : 1.06
This library is use to create a basic controller class for MinimaList API Server v2.03+ template.

Library:
  • MinimaListController.jar
  • MinimaListController.xml
GitHub:
https://github.com/pyhoon/MinimaListController-B4J

Generated code:
SampleController:
' MinimaList Controller
' Version 1.06
Sub Class_Globals
    Private Request As ServletRequest
    Private Response As ServletResponse
    Private HRM As HttpResponseMessage
    Private Method As String
    Private Version As String
    Private Elements() As String
    Private ApiVersionIndex As Int
    Private ControllerIndex As Int
    Private ElementLastIndex As Int
    'Private FirstIndex As Int
    'Private FirstElement As String
End Sub

Public Sub Initialize (req As ServletRequest, resp As ServletResponse)
    Request = req
    Response = resp
    HRM.Initialize
End Sub

Private Sub ReturnBadRequest 'ignore
    WebApiUtils.ReturnBadRequest(Response)
End Sub

Private Sub ReturnApiResponse 'ignore
    WebApiUtils.ReturnHttpResponse(HRM, Response)
End Sub

Private Sub ReturnMethodNotAllow 'ignore
    WebApiUtils.ReturnMethodNotAllow(Response)
End Sub

Private Sub ReturnErrorUnprocessableEntity 'ignore
    WebApiUtils.ReturnErrorUnprocessableEntity(Response)
End Sub

' API Router
Public Sub RouteApi
    Method = Request.Method.ToUpperCase
    Elements = WebApiUtils.GetUriElements(Request.RequestURI)
    ElementLastIndex = Elements.Length - 1
    ApiVersionIndex = Main.Element.ApiVersionIndex
    Version = Elements(ApiVersionIndex)
    ControllerIndex = Main.Element.ApiControllerIndex
    'If ElementLastIndex > ControllerIndex Then
    '    FirstIndex = ControllerIndex + 1
    '    FirstElement = Elements(FirstIndex)
    'End If
  
    Select Method
        Case "GET"
            'RouteGet
        Case "POST"
            'RoutePost
        Case "PUT"
            'RoutePut
        Case "DELETE"
            'RouteDelete
        Case Else
            Log("Unsupported method: " & Method)
            ReturnMethodNotAllow
    End Select
End Sub

Tutorial:

Release Logs
  • Version 1.06
    • (add) ReturnBadRequest sub
    • (add) ReturnMethodNotAllow sub
    • (add) ReturnErrorUnprocessableEntity sub

This project has been tested many many times. Please report bugs if you found any
Post your question in a new thread.


Note: This library was created on 23/09/2023 (more than 7 months) as an attachment for Web API Server (v2.04+) template. This new thread is to make the dependencies more organized and for future updates.
 

Attachments

  • MinimaListController.jar
    788 bytes · Views: 8
  • MinimaListController.xml
    326 bytes · Views: 7
Last edited:
Top