Code Monkey home page Code Monkey logo

micron's Introduction

Micron

TravisCI

Description

Minimal .net core framework based on three tier architecture, can be used as template for building API's

I've built this framework mostly for myself with all needed features out of the box, but this foundation can be more modular to have more potential use cases.

Features

Example route with validation

Get("/api/v1/item/get", _ => {
    var errors = ValidationProcessor.Process(Request, new IValidatorRule[] {
        new ExistsInTable("item_guid", "items", "guid"),
    });
    if (errors.Count > 0) {
        return HttpResponse.Errors(errors);
    }

    return HttpResponse.Item("item", new ItemTransformer().Transform(
        ItemRepository.FindByGuid(Request.Query["item_guid"])
    ));
});

Example controller with middleware (check JWT token)

public class ItemCrudController : BaseController {
    protected override IMiddleware[] Middleware() => new IMiddleware[] {
        new JwtMiddleware()
    };
    
    public ItemCrudController() {
        Post("/api/v1/item/create", _ => {
            var errors = ValidationProcessor.Process(Request, new IValidatorRule[] { });
            if (errors.Count > 0) {
                return HttpResponse.Errors(errors);
            }

            var item = ItemRepository.CreateAndGet((string) Request.Query["title"], (float) Request.Query["price"]);

            return HttpResponse.Item("item", new ItemTransformer().Transform(item));
        });
    }
}

Example transformer

public class ItemTransformer : BaseTransformer {
    public override JObject Transform(object obj) {
        var item = (ItemModel) obj;
        return new JObject {
            ["guid"] = item.guid,
            ["title"] = item.title,
            ["price"] = item.price,
        };
    }
}

Tech summary:

Supported databases: PostgreSQL


System requirements:

  • .net core > 2.2
  • database (PostgreSql only)
  • PHP > 7.0 (for migrations)

Project structure:

Foundation of the framework is located in framework-base-core and loaded as submodule into Base project


Used tools:

Database:


Set up:

  1. build project
  2. copy config.example.json into:
  • For main app
  • App/bin/%BUILD_TYPE%/netcoreapp2.2/config/config.json
  • For unit tests
  • Tests/bin/%BUILD_TYPE%/netcoreapp2.2/config/config.json Example: App/bin/Debug/netcoreapp2.2/config/config.json
  1. edit config files - fill db name / user / etc.

Migrating

  1. copy migrations/phinx.example.yml to migrations/phinx.yml
  2. edit phinx.yml - fill database user / password etc.
  3. install php & composer dependencies from migrations/composer.json
  4. run migrations (in migrations folder):

php vendor/bin/phinx migrate - to migrate with default database (development)

php vendor/bin/phinx migrate -e testing - to migrate with test database

Building & running project

You should be able to build with dotnet build and run app via for example: dotnet App/bin/Debug/netcoreapp2.2/App.dll

Contribution:

Thank you for considering contributing to this repo. Feel free to submit any improvements / issues / refactoring / documentation etc.

micron's People

Contributors

eliamartani avatar mx2s avatar

Watchers

 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.