Skip to content

Instantly share code, notes, and snippets.

@nielsbosma
Last active March 7, 2017 15:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nielsbosma/a30767492f72c41970d57be5af35f359 to your computer and use it in GitHub Desktop.
Save nielsbosma/a30767492f72c41970d57be5af35f359 to your computer and use it in GitHub Desktop.
LinqPad Nancy Example
void Main()
{
var configuration = new HostConfiguration() { UrlReservations = new UrlReservations() { CreateAutomatically = true } };
using (var host = new Nancy.Hosting.Self.NancyHost(new Uri("http://localhost:8090"), new LinqpadNancyBootstrapper(), configuration))
{
host.Start();
Console.ReadLine();
}
}
public class HelloModule : Nancy.NancyModule
{
public HelloModule(TypedDataContext db)
{
Get["/user-by-email/{email}"] = p =>
{
string email = (string)p.email;
return _GetUserResponse(db.AspNetUsers.Where(e => e.UserName.Equals(email)));
};
}
private Nancy.Response _GetUserResponse(IQueryable<AspNetUsers> linq)
{
var user = linq.Select(e => new
{
Id = e.Id,
FirstName = e.FirstName,
LastName = e.LastName,
UserName = e.UserName
}).FirstOrDefault();
return Response.AsJson(user);
}
}
public class LinqpadNancyBootstrapper : Nancy.DefaultNancyBootstrapper
{
protected override void ConfigureApplicationContainer(Nancy.TinyIoc.TinyIoCContainer container)
{
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment