Skip to content

Repository files navigation

Nancy.Rest.Module

A Nancy Module capable of mounting an annotated interface and provides transversal filtering capabilities.

Installation

Or

Basic Usage

####Create your Server signatures:

namespaceNancy.Rest.ExampleServer{[RestBasePath("/api")]publicinterfaceIExample{[Rest("Person",Verbs.Get)]List<Person>GetAllPersons();[Rest("Person/{personid}",Verbs.Get)]PersonGetPerson(intpersonid);[Rest("Person",Verbs.Post)]boolSavePerson(Personperson);[Rest("Person/{personid}",Verbs.Delete)]boolDeletePerson(intpersonid);}}

####And Your Server Models

namespaceNancy.Rest.ExampleServer{publicclassPerson{publicstringFirstName{get;set;}publicstringLastName{get;set;}[Level(1)]publicboolIsProgrammer{get;set;}[Tags("Attr")]publicList<string>Attributes{get;set;}}}

The following annotations exists:

  • RestBasePath - The default path using to mount the module in Nancy.
  • Rest - Here you can add the route path, the verb, and optionally the response content-type in case of streams.
  • Level - For transversal serialization, when a client sent the level={number} as a query parameter, any property in the models with level bigger than the one asked by the client, will be not sent to the client.
  • Tag - For transversal serialization, when a client sent the excludetags={comma_separated_tags) as a query parameter, any property in the model with the tags included will be not serialized and sent back to the client.
  • Ignore - The property will be not serialized and sent back to the client.

Example Server

Your Server Implementation
namespaceNancy.Rest.ExampleServer{publicclassExampleImplementation:IExample{publicList<Person>GetAllPersons{//TODO }publicPersonGetPerson(intpersonid){//TODO }publicboolSavePerson(Personperson){//TODO}publicboolDeletePerson(Personperson){//TODO}}}
Bootstrapper
namespaceNancy.Rest.ExampleServer{publicclassBootstrapper:RestBootstrapper{}}
Module
namespaceNancy.Rest.ExampleServer{publicclassExampleModule:RestModule{publicExampleModule(){SetRestImplementation(newExampleImplementation());}}}
Running Nancy selfhosted
publicclassExample{publicvoidRun(){HostConfigurationconfig=newHostConfiguration();config.UrlReservations.CreateAutomatically=false;config.RewriteLocalhost=true;NancyHosthostNancy=newNancy.Hosting.Self.NancyHost(config,newUri("http://localhost"));hostNancy.Start();}}}

###To use the server in C# clients without much trouble and dynamic client proxy generation please continue reading how to use the client in Nancy.Rest.Client

History

1.4.3-Beta: Removed bugs, Added StreamWithResponse class, for finetunning Stream responses, published nugets.

1.4.3-Alpha: First Release

##WARNING

THIS IS AN BETA VERSION, so far it works on my machine ;)

TODO

  • Claim/Role based transversal filtering
  • Swagger!
  • Squash Bugs
  • Squash More Bugs
  • Pray
  • Change Bugs issues to features
  • TODO :P

##MAYBE

  • Added secure module and secure client, wrapping request and responses models with signatures.

Built With

Credits

License

This project is licensed under the MIT License - see the LICENSE.md file for details

About

A Nancy Module capable of mounting an annotated interface.

Resources

Stars

5 stars

Watchers

7 watching

Forks

Releases

Packages

Used by

Contributors

Languages