Aqueduct is a server-side framework written in Dart.
-
Activate Aqueduct
pub global activate aqueduct
-
Run first time setup.
aqueduct setup
-
Create a new project.
aqueduct create -n my_project
Open the project directory in the editor of your choice. Our preferred editor is IntellIJ IDEA Community Edition (with the Dart Plugin). Atom is also a good editor, but support for running Dart tests is lacking.
- HTTP Request Routing and Middleware
- Multiple CPU support, without adding complicated multi-threading logic.
- CORS Support.
- Automatic OpenAPI specification/documentation generation.
- OAuth 2.0 implementation.
- Fully-featured ORM, with clear, type- and name-safe syntax, and SQL Join support. (Supports PostgreSQL by default.)
- Database migration tooling.
- Template projects for quick starts.
- Integration with CI tools. (Supports TravisCI by default.)
- Integrated testing utilities for clean and productive tests.
- Logging to Rotating Files or Console
Need a walkthrough? Read the tutorials. They take you through the steps of building an Aqueduct application.
You can find the API reference here. You can find in-depth guides and tutorials here.
The following is a complete application, with endpoints to create, get, update and delete 'Notes' that are stored in a PostgreSQL database.
import 'package:aqueduct/aqueduct.dart';
void main() {
var app = new Application<AppRequestSink>();
app.start(numberOfInstances: 3);
}
class AppRequestSink extends RequestSink {
AppRequestSink(Map<String, dynamic> opts) : super(opts) {
logger.onRecord.listen((p) => print("$p"));
var dataModel =
new ManagedDataModel.fromPackageContainingType(this.runtimeType);
var psc = new PostgreSQLPersistentStore.fromConnectionInfo(
"dart", "dart", "localhost", 5432, "dart_test");
ManagedContext.defaultContext = new ManagedContext(dataModel, psc);
}
@override
void setupRouter(Router router) {
router
.route("/notes[/:id]")
.generate(() => new ManagedObjectController<Note>());
}
}
class Note extends ManagedObject<_Note> implements _Note {}
class _Note {
@managedPrimaryKey
int id;
String contents;
}
Want to try this out? Save this code in a file named main.dart
. In the same directory, create a pubspec.yaml
file with the following contents:
name: app
dependencies:
aqueduct: any
Connect to postgres://dart:dart@localhost:5432/dart_test
and create a table (with this exact name) just like this:
create table _note (id bigserial primary key, contents text);
Now, run it:
pub get
dart main.dart
And now you can make requests:
# Create a new note: POST /notes
curl -X POST http://localhost:8080/notes -H "Content-Type: application/json" -d '{"contents" : "a note"}'
# Get that note: GET /notes/1
curl -X GET http://localhost:8080/notes/1
# Change that note: PUT /notes/1
curl -X PUT http://localhost:8080/notes/1 -H "Content-Type: application/json" -d '{"contents" : "edit"}'
# Delete that note:
curl -X DELETE http://localhost:8080/notes/1
# Note there are no more notes:
curl -X GET http://localhost:8080/notes