Git Product home page Git Product logo

aspnetcoreapiutilities's Introduction

AspNetCoreApiUtilities

CircleCI #

AspNetCore Api Utilities for asp.net core that include things like an Exception Handler middleware, modelstate validation by attribute, RequireNonDefault attribute for controller models, and swagger operation filters for 400 and 500.

Getting started

Install the package

Install the nuget package from nuget

Either add it with the PM-Console:

    Install-Package Frogvall.AspNetCore.ApiUtilities

Or add it to csproj file ->

        <ItemGroup>
                ...
                <PackageReference Include="Frogvall.AspNetCore.ApiUtilities" Version="x.y.z" /> 
                ...
        </ItemGroup>

Using the utilites

Edit your Startup.cs ->

    Configure(){
       ...

       app.UseApiExceptionHandler

       ...
    }

Add to controller method ->

    [ValidateModel]

Add to controller model (dto) property ->

    [RequireNonDefault]        

Add to swagger spec ->

    options.OperationFilter<ValidateModelOperationFilter>();
    options.OperationFilter<InternalServerErrorOperationFilter>();

Throw when returning non 2xx ->

    throw new ApiException(HttpStatusCode.<statuscode>, <message>);

Build and Publish

Prequisites

The package is build in docker so you will need to install docker to build and publish the package. (Of course you could just build it on the machine you are running on and publish it from there. I prefer to build and publish from docker images to have a reliable environment, plus make it easier to build this on circleci).

build

run: docker-compose -f docker-compose-build.yml up

this will build & test the code. The testresult will be in folder ./testresults and the package in ./package

! if you clone the project on a windows machine you will have to change the file endings on the build-container.sh to LF

publish

run: (fill in the api key):

    docker run --rm -v ${PWD}/package:/data/package schwamster/nuget-docker push /data/package/*.nupkg <your nuget api key> -Source nuget.org

this will take the package from ./package and push it to nuget.org

build on circleci

The project contains a working circle ci yml file. All you have to do is to configure the Nuget Api Key in the build projects environment variables on circleci (Nuget_Api_Key)

aspnetcoreapiutilities's People

Contributors

frogvall avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.