spark_framework 1.0.0-alpha.1
spark_framework: ^1.0.0-alpha.1 copied to clipboard
Lightweight isomorphic SSR framework for Dart with Custom Elements and Declarative Shadow DOM
example/example.md
Spark Example #
This directory contains a complete example application built with the Spark framework.
Features Demonstrated #
- Server Setup: Basic server configuration with logging and middleware (
bin/server.dart). - Endpoint Definition: Creating endpoints using the
@Endpointannotation (lib/endpoints/endpoints.dart). - Request Handling:
- Typed request bodies (
EchoUserEndpoint) - Map/dynamic request bodies (
EchoDetailsEndpoint) - Path parameters (
GetUserEndpoint)
- Typed request bodies (
- Middleware: Applying middleware to specific endpoints (
CheckMwEndpoint). - OpenAPI: Automatic OpenApi specification generation.
Running the Example #
-
Get dependencies:
dart pub get -
Start the server:
First, install the
spark_cli(if not already installed):dart pub global activate spark_cliThen run the development server:
spark devYou should see output indicating the server is running, e.g.,
Server running at http://localhost:9003. -
Test Endpoints:
-
Hello World:
GET http://localhost:9003/api/hello -
Echo User (POST):
POST http://localhost:9003/api/echo Body: { "name": "Alice123456" }
-
-
View OpenAPI Spec: To generate the OpenAPI specification, run:
spark openapiThe
openapi.jsonfile is generated in the root of the example directory. -
Build for Production: To build the project for production, run:
spark build
Directory Structure #
bin/: Contains the server entry point.lib/endpoints/: Defines the API endpoints and DTOs.lib/pages/: Contains the application pages (for server-side rendering).lib/components/: Example UI components (if applicable).