Last active
March 7, 2017 15:56
-
-
Save nielsbosma/a30767492f72c41970d57be5af35f359 to your computer and use it in GitHub Desktop.
LinqPad Nancy Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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