public String Id { get; set; }
Handle.GET("/hello/{?}", (Request req, Int32 id) => {
// As we are on Starcounter thread already, we can create a database object.
// Notice that we use `Db.TransactAsync` here. Read about it in a separate article.
Db.TransactAsync(() => new Person() { Id = id.ToString() });
// Now we run an async task that will return the response later.
DoSomethingAsync(req, id);
// Indicating that HTTP response will be returned later.
return HandlerStatus.Handled;
// Async call that does some await and performs database operations after.
static async void DoSomethingAsync(Request req, Int32 id) {
// Now using async to simulate some long operation using await statement.
// Since this is not a Starcounter thread now, so we need to schedule
// a Starcounter task so we can do our database operations.
await Scheduling.RunTask(() => {
var person = Db.SQL<Person>("SELECT p FROM Person p WHERE p.Id = ?", id.ToString()).FirstOrDefault();
// Doing some database operations.
// Notice that we use `Db.TransactAsync` here. Read about it in a separate article.
Db.TransactAsync(() => person.Id += id);
// Now in continuation we need to perform some other Starcounter operations
// therefore we need to use `Scheduling.RunTask` again.
await Scheduling.RunTask(() => {
// Finally returning the response.
Response resp = new Response() {
Body = "Done with object " + id