Class HTTPRoute

java.lang.Object
io.github.sigmacasino.HTTPRoute
All Implemented Interfaces:
spark.Route
Direct Known Subclasses:
GetRoute, PostRoute

public abstract class HTTPRoute extends Object implements spark.Route
HTTPRoute is an abstract class that represents a route in the HTTP server. It is a wrapper around the Spark Route interface, and is used to provide a common fields for all routes in the server.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final App
    The App object that the route is associated with.
    protected boolean
    Whether the route requires the user to be logged in.
    protected final String
    The path of the route, e.g.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    HTTPRoute(App app, String path)
    Constructor for the HTTPRoute class.
  • Method Summary

    Modifier and Type
    Method
    Description
    handle(spark.Request request, spark.Response response)
    Handles the request and returns the response.
    abstract void
    Registers the route with Spark.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • app

      protected final App app
      The App object that the route is associated with.
    • path

      protected final String path
      The path of the route, e.g. "/account/reset_password". This is the path that the route will be registered to with Spark.
    • loginRequired

      protected boolean loginRequired
      Whether the route requires the user to be logged in.
  • Constructor Details

    • HTTPRoute

      protected HTTPRoute(App app, String path)
      Constructor for the HTTPRoute class.
      Parameters:
      app - The App object that the route is associated with.
      path - The path of the route.
  • Method Details

    • handle

      public Object handle(spark.Request request, spark.Response response) throws Exception
      Handles the request and returns the response. This method is called by Spark when a request is made to the route. It should be overridden by subclasses to provide the route's functionality. Additionally, this super-implementation handles redirecting the user to the login page if the route requires the user to be logged in and returns boolean which says whether the redirect should occur.
      Specified by:
      handle in interface spark.Route
      Parameters:
      request - The request object.
      response - The response object.
      Returns:
      The response object, which might be text, HTTP code, etc.
      Throws:
      Exception - If an error occurs while handling the request.
      See Also:
      • Route.handle(Request, Response)
    • registerSparkRoute

      public abstract void registerSparkRoute()
      Registers the route with Spark.