Angel 2 is out now! Brings Dart 2 support, GraphQL support, and more. Read more .
# Install the Angel CLI, and scaffold a project.
$ pub global activate angel_cli
$ angel init hello
import 'package:angel_framework/angel_framework.dart';
import 'package:angel_framework/http.dart';
main() async {
var app = Angel(), http = AngelHttp();
app
..get('/', (req, res) => res.writeln('Hello, Angel!'));
..fallback((req, res) => throw AngelHttpException.notFound());
await http.startServer('127.0.0.1', 3000);
print('Listening at ${http.uri}');
}
@Expose('/accounts')
class AccountsController extends Controller {
// Auto-injected by Angel
final QueryExecutor executor;
AccountsController(this.executor);
@Expose('/:username/profile')
renderProfile(String username, ResponseContext res) async {
var query = UserQuery()..where.username.equals(username);
var user = await query.getOne(executor);
await res.render('profile', {'user': user});
}
}
void main() {
TestClient client;
setUp(() async {
var app = Angel();
await app.configure(myApp.configureServer);
client = await connectTo(app);
});
tearDown(() => client.close());
test('cannot view secret content', () async {
var response = await client.get('/secret');
expect(response, hasStatus(403));
});
}