Class BodyRegistry

java.lang.Object
de.craftsblock.craftsnet.api.http.body.BodyRegistry

public class BodyRegistry extends Object
This class represents a registry for body parsers used in HTTP request processing. It allows registering parsers for different types of request bodies, and provides methods to retrieve and check the presence of a parser for a given body type.
Since:
3.0.4-SNAPSHOT
See Also:
  • Constructor Details

    • BodyRegistry

      public BodyRegistry()
      Constructs a new BodyRegistry and registers default body parsers for common body types. This constructor initializes the registry with parsers for JSON, multipart form, and standard form bodies.
  • Method Details

    • register

      public <T extends Body> void register(@NotNull @NotNull BodyParser<T> bodyParser)
      Registers a body parser for a specific body type.
      Type Parameters:
      T - The type of body being parsed.
      Parameters:
      bodyParser - The body parser for the specified body type.
    • isRegistered

      public boolean isRegistered(BodyParser<? extends Body> loader)
      Checks if the given BodyParser is registered. This class is a wrapper for isRegistered(Class).
      Parameters:
      loader - The BodyParser to check.
      Returns:
      true when the BodyParser was registered, false otherwise.
      Since:
      3.2.1-SNAPSHOT
    • isRegistered

      public boolean isRegistered(Class<? extends BodyParser<? extends Body>> type)
      Checks if the given class representation of the BodyParser is registered.
      Parameters:
      type - The class representation of the BodyParser to check.
      Returns:
      true when the BodyParser was registered, false otherwise.
      Since:
      3.2.1-SNAPSHOT
    • getParser

      public <T extends Body> BodyParser<T> getParser(@NotNull @NotNull Class<T> type)
      Retrieves the body parser associated with the specified body type.
      Type Parameters:
      T - The type of body being parsed.
      Parameters:
      type - The class representing the body type.
      Returns:
      The body parser for the specified body type, or null if not found.
    • isParserPresent

      public <T extends Body> boolean isParserPresent(@NotNull @NotNull Class<T> type)
      Checks if a parser is registered for the specified body type.
      Type Parameters:
      T - The type of body being parsed.
      Parameters:
      type - The class representing the body type.
      Returns:
      true if a parser is registered for the specified body type, false otherwise.