Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

License

NotificationsYou must be signed in to change notification settings

SRoddis/Nancy.RestModule

Repository files navigation

Build statusCoverage Status

Nancy.RestModule

Nancy.RestModule is designed to create REST resources in a fast and simple way with NancyFx. TheRestModule decouples theNancyModule from your self-implemented controller, so the controller can be tested easily.

Nancy.RestModule can handleDELETE,GET,POST andPUT requests and provides a simple JSON.With the generic request handlers you are able to define your API interface by simpleRequestModels which are bind automatically from NancyFx.

Installation

Install via nugethttps://www.nuget.org/packages/Nancy.RestModule

PM> Install-Package Nancy.RestModule

How to use

  1. Create yourRestModule in your NancyFx-Application.

    publicclassCustomerModule:RestModule{publicCustomerModule():base("/customer"){}}
  2. Create your customController and register it to theDIContainer.Now theController can be easily tested withUnitTests withoutNancy.Testing

    publicclassCustomerController:ICustomerController{privatereadonlyICustomerService_service;publicCustomerController(ICustomerServiceservice){_service=service;}publicResponseModelGetList(){IEnumerable<ICustomer>customers=_service.FindAll();returncustomers.CreateResponse();}publicResponseModelGet(GetCustomerRequestcustomerRequest){ICustomercustomer=_service.Find(customerRequest.Id);returncustomer.CreateResponse();}// ... etc.}
  3. Inject the controller in the module and define your routes and models.Now you can define your REST interface without pushing everything in theNancyModule.

    publicclassCustomerModule:RestModule{publicCustomerModule(ICustomerControllercontroller):base("/customer"){GetHandler("/",controller.GetList);GetHandler<GetCustomerRequest>("/{id}",controller.Get);PostHandler<PostCustomerRequest>("/",controller.Post);PutHandler<PutCustomerRequest>("/{id}",controller.Put);}}

Compile, run and enjoy the simplicity!

Demo

In the repository you can findNancy.RestModule.Demo which is a simple demo to show how to use Nancy.RestModule.

  1. Compile and run the demo application.
  2. Now you canlist all customers and should get the following response.
    [    {"id":<Guid>,"firstName":"Jeff","lastName":"Dunham","age":56,"created":<current datetime>    },    {"id":<Guid>,"firstName":"Lee","lastName":"Evans","age":53,"created":<current datetime>    },    {"id":<Guid>,"firstName":"John","lastName":"Cleese","age":79,"created":<current datetime>    }]
  3. (Optional) Change the resource withPUT andPOST

Copyright

Copyright © 2017 Sean Roddis

License

Nancy.RestModule is licensed underMIT. Refer to license.txt for more information.

About

No description or website provided.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp