Dartcore is a minimalist, yet powerful HTTP server framework for the Dart programming language. It provides a simple API for routing and handling HTTP requests, making it perfect for lightweight (not very, can be used for complex ones that will never crash) web applications, APIs, or microservices.
- Simple and intuitive routing
- Lightweight and fast
- Minimal dependencies
- Easy to use for building RESTful APIs
- Customizable request handling
- Looks a bit like Flask :)
First, ensure you have the Dart SDK installed. Then, add dartcore to your pubspec.yaml file as a dependency.
dependencies:
dartcore: anyRun dart pub get to install dependencies.
You can install it by running the command:
dart pub activate global dartcoreand then try,
dartcore --versionFollow these simple steps to set up your Dartcore server.
import 'package:dartcore/dartcore.dart' as dartcore;
// "" is the config file path
final app = dartcore.App(debug: true); // replace true with false in production mode! this specifies Debugging modeUse the route method to handle incoming HTTP requests. Specify the HTTP method (e.g., GET, POST, etc.) and the route.
app.route('GET', '/', (req, res) {
res.send("Hello from Dartcore!", ContentType.text);
});
app.route('GET', '/hello', (req, res) {
res.json({"from":"Dartcore","message":"Hello World!"});
});Use the start method to start the server.
app.start(port: 8080);- (String)
address: The server's IP address (default:0.0.0.0--> All IP Addresses). - (int)
port: The port on which the server listens (default:8080).
See the full example on pub.dev!
Run your Dart server with:
dart runVisit http://127.0.0.1:8080/, http://localhost:8080/, or http://YOUR_PRIVATE_IP:8080/ to see the server in action!
Contributions are welcome! Please feel free to submit issues and pull requests to help improve DartCore.
This project is licensed under the MIT License - see the LICENSE file for details.