Skip to content

goncalo-oliveira/rest-schema-aspnet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RESTful Schema Extensions for ASP.NET

An ASP.NET implementation for the REST Schema Spec. This is still a work in progress and it currently implements v0.2 of the spec.

Features:

  • Schema-Mapping
  • Schema-Include
  • Headers
  • Query string parameters
  • JSON schema
  • Plain text schema
  • Schema filters

Getting Started

The fastest way is to add the NuGet package to your ASP.NET project.

$ dotnet add package RestSchema --version 0.2.0-preview-1

Alternatively, you can checkout this repository as a submodule and then add a reference to the project.

$ git submodule add git@github.com:goncalo-oliveira/rest-schema-aspnet.git
$ dotnet add reference rest-schema-aspnet/src/rest-schema-aspnet.csproj

In the project's Startup class, change the MVC Controllers configuration replacing AddControllers with AddSchemaControllers.

public void ConfigureServices( IServiceCollection services )
{
    services.AddSchemaControllers();
    ...
}

Schema-Include

To handle with the Schema-Include you can use the extensions on the HttpRequest to verify if a property is to be included. Here's an example to retrieve a user's details and include the user's teams if included in the schema.

public class UserController : ControllerBase
{
    ...

    public IActionResult GetUser( int id )
    {
        // retrieve the user's details
        var user = ExampleUserRepository.GetUser( id );

        // include the user's teams
        if ( Request.SchemaIncludes( "teams" ) )
        {
            user.Teams = ExampleTeamRepository.GetUserTeams( id );
        }

        return Ok( user );
    }
}

About

RESTful Schema Extensions for ASP.NET

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published

Languages