Nancy.Rest.Module 1.4.3.7-beta

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

This is a prerelease version of Nancy.Rest.Module.
Install-Package Nancy.Rest.Module -Version 1.4.3.7-beta
dotnet add package Nancy.Rest.Module --version 1.4.3.7-beta
<PackageReference Include="Nancy.Rest.Module" Version="1.4.3.7-beta" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Nancy.Rest.Module --version 1.4.3.7-beta
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

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:


namespace Nancy.Rest.ExampleServer
{
    [RestBasePath("/api")]
    public interface IExample
    {
        [Rest("Person", Verbs.Get)]
        List<Person> GetAllPersons();
        
        [Rest("Person/{personid}", Verbs.Get)]
        Person GetPerson(int personid);
        
        [Rest("Person", Verbs.Post)]
        bool SavePerson(Person person);

        [Rest("Person/{personid}", Verbs.Delete)]
        bool DeletePerson(int personid);
    }
}

####And Your Server Models


namespace Nancy.Rest.ExampleServer
{    
    public class Person
    {
        public string FirstName { get; set; }

        public string LastName { get; set; }
        
        [Level(1)]
        public bool IsProgrammer { get; set; }
        
        [Tags("Attr")]
        public List<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

namespace Nancy.Rest.ExampleServer
{
    public class ExampleImplementation : IExample
    {
        public List<Person> GetAllPersons
        {
        //TODO        
        }
        
        public Person GetPerson(int personid)
        {
        //TODO                
        }
        
        public bool SavePerson(Person person)
        {
        //TODO
        }
        
        public bool DeletePerson(Person person)
        {
        //TODO
        }
    }
}
Bootstrapper

namespace Nancy.Rest.ExampleServer
{
    public class Bootstrapper : RestBootstrapper
    {
    
    }
}   

Module

namespace Nancy.Rest.ExampleServer
{   
    public class ExampleModule : RestModule
    {
        public ExampleModule()
        {
            SetRestImplementation(new ExampleImplementation());
        }
    }

}
Running Nancy selfhosted

    public class Example
    {
        public void Run()
        {
            HostConfiguration config = new HostConfiguration();
            config.UrlReservations.CreateAutomatically = false;
            config.RewriteLocalhost = true;
            NancyHost hostNancy = new Nancy.Hosting.Self.NancyHost(config, new Uri("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

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:


namespace Nancy.Rest.ExampleServer
{
    [RestBasePath("/api")]
    public interface IExample
    {
        [Rest("Person", Verbs.Get)]
        List<Person> GetAllPersons();
        
        [Rest("Person/{personid}", Verbs.Get)]
        Person GetPerson(int personid);
        
        [Rest("Person", Verbs.Post)]
        bool SavePerson(Person person);

        [Rest("Person/{personid}", Verbs.Delete)]
        bool DeletePerson(int personid);
    }
}

####And Your Server Models


namespace Nancy.Rest.ExampleServer
{    
    public class Person
    {
        public string FirstName { get; set; }

        public string LastName { get; set; }
        
        [Level(1)]
        public bool IsProgrammer { get; set; }
        
        [Tags("Attr")]
        public List<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

namespace Nancy.Rest.ExampleServer
{
    public class ExampleImplementation : IExample
    {
        public List<Person> GetAllPersons
        {
        //TODO        
        }
        
        public Person GetPerson(int personid)
        {
        //TODO                
        }
        
        public bool SavePerson(Person person)
        {
        //TODO
        }
        
        public bool DeletePerson(Person person)
        {
        //TODO
        }
    }
}
Bootstrapper

namespace Nancy.Rest.ExampleServer
{
    public class Bootstrapper : RestBootstrapper
    {
    
    }
}   

Module

namespace Nancy.Rest.ExampleServer
{   
    public class ExampleModule : RestModule
    {
        public ExampleModule()
        {
            SetRestImplementation(new ExampleImplementation());
        }
    }

}
Running Nancy selfhosted

    public class Example
    {
        public void Run()
        {
            HostConfiguration config = new HostConfiguration();
            config.UrlReservations.CreateAutomatically = false;
            config.RewriteLocalhost = true;
            NancyHost hostNancy = new Nancy.Hosting.Self.NancyHost(config, new Uri("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

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.4.3.7-beta 1,765 10/3/2017