Code Monkey home page Code Monkey logo

zen's Introduction

Zen is platform-independent .NET Core middleware that simplifies the implementation of data-driven, API-focused apps.

Publish NuGet packages

Oh, c'mon! Yet another do-it-all framework? Really?

Not quite. Zen provides several features like ORM, caching, encryption and RESTful endpoints out of the box with zero setup in most cases. Think of it like a drop-in middleware that'll get your PoC app working with persistent storage to REST endpoints in no time and with minimal scaffolding - and you can add more features as the need arises.

Its core aspect is the ability to handle data for multiple connectors at the same time, regardless of the target database: Both relational and document (no-SQL) models are supported. Pull data from Oracle and write to Mongo, this kind of stuff.

Something basic: a database-backed console app

To have it working straight out of the box we need Zen.Base (the ORM handler) and a database adapter; let's pick Zen.Module.Data.LiteDB for this example.

Extremely complicated example ahead. Pay attention!

  • Create a class that inherits from the Zen.Base.Module.Data<> generic class;
  • Mark the property you want to use as a unique identifier with the [Key] Data Annotation attribute.

C# example:

using System.ComponentModel.DataAnnotations;
using System;
using Zen.Base.Module;

namespace Test
{
    public class Person : Data<Person>
    {
        [Key]
        public string Id { get; set; }
        public string Name { get; set; }
    }
}

W-wait, what have I just done?

Congratulations! You created a LiteDB-backed ORM class. A default database was created, together with a collection to store entries.

You mentioned something about REST

Oh, REST! Right. So, once you decide you want to expose your ORM class data through a REST endpoint, do this:

  • Add a reference to ๐Ÿ“ฆ Zen.Web
  • Add Zen to the Service collection and configure it with the Application builder:
using Zen.Base.Service.Extensions;
public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    { services.AddZen(); }
    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    { app.UseZen(); }
}
  • Use the simplified Builder:
using Zen.Web.Host;
namespace Sample
{
    public class Program
    {
        public static void Main(string[] args)
        { Builder.Start<Startup>(args); }
    }
}
  • Implement a class deriving from Zen.Web.Data.Controller.DataController<>, and assign a route to it:
[Route("api/people")]
public class PersonController : DataController<Person> {}
  • ...and that's it.

DataController<> implements standard REST operations (GET, GET/{ID}, POST, DELETE, PATCH) as well as some useful extentions (e.g. GET/new). These can be expanded by modules that offer functionalities like moderation and set versioning.

Now run your project, and reach the endpoint you specified. If you're running the sample provided (Sample02-REST), you can try the following URLs:

  • https://localhost:5001/api/people
[{"Id":"1","Name":"Halie","LastName":"Ebert","Email":"[email protected]"},{"Id":"2","Name":"Meta","LastName":"Mayert","Email":"[email protected]"},{"Id":"3","Name":"Deonte","LastName":"Orn","Email":"[email protected]"},,(...)
  • https://localhost:5001/api/people/1
{"Id":"1","Name":"Halie","LastName":"Ebert","Email":"[email protected]"}
  • https://localhost:5001/api/people/new
{"Id":"fc8dbb27-42fe-45db-be09-18a84361d509","Name":null,"LastName":null,"Email":null}

Core dependencies

The relational Data module wraps around Stack Exchange Dapper, an abusively fast IDbConnection interface extender.

Zen Development Team

License

MIT - a permissive free software license originating at the Massachusetts Institute of Technology (MIT), it puts only very limited restriction on reuse and has, therefore, an excellent license compatibility. It permits reuse within proprietary software provided that all copies of the licensed software include a copy of the MIT License terms and the copyright notice.

Check the LICENSE file for more details.

zen's People

Contributors

dependabot[bot] avatar lbotinelly avatar leonaquitaine avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

zen's Issues

Documentation

Hello !

The library seems great and I'd like to use it in my projects but there is no documentation except the README and a few samples. Are you planning on providing a more detailled documentation (for example on using GraphQL) ?

Cheers !
Jules

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.