ApiCat is a lightweight api web framework built on top of Deno. It provides a simple and intuitive API for creating web applications with features like routing, middleware support, error handling, and more.
To use ApiCat in your Deno project, you need to import it from your project file:
import { ApiCat } from "./path/to/ApiCat.ts";
Make sure you have Deno installed and the Oak dependency is available.
Here's a simple example of how to use ApiCat:
import { ApiCat } from "./ApiCat.ts";
const app = new ApiCat();
app.get("/", (ctx) => {
ctx.response.body = "Hello, ApiCat!";
});
app.listen(8000);
new ApiCat()
Creates a new instance of the ApiCat application.
ApiCat provides methods for different HTTP verbs:
get(path: string, ...handlers: RouteHandler[])
post(path: string, ...handlers: RouteHandler[])
put(path: string, ...handlers: RouteHandler[])
delete(path: string, ...handlers: RouteHandler[])
patch(path: string, ...handlers: RouteHandler[])
all(path: string, ...handlers: RouteHandler[])
Each method takes a path and one or more handler functions.
use(middleware: MiddlewareFn)
Adds middleware to the application.
handleError(handler: (ctx: Context<State>, error: Error) => void)
Sets up a global error handler for the application.
validate(schema: Record<string, (value: string | null) => boolean>)
Creates a middleware for validating request parameters based on the provided schema.
getQueryParams(ctx: Context<State>): Record<string, string | null>
Retrieves all query parameters from the request.
setResponseHeaders(headers: Record<string, string>)
Sets global response headers for all routes.
cors(options: CorsOptions = {})
Creates a middleware for handling Cross-Origin Resource Sharing (CORS).
static(root: string)
Creates a middleware for serving static files from a specified directory.
listen(port: number)
Starts the server on the specified port.
This project is licensed under the MIT License.