Giter Club home page Giter Club logo

chimera's Introduction

chimera

Chi-based Module for Easy REST APIs

Overview

chimera is designed for fast/easy API development based on OpenAPI with the following core features:

  • Automatic OpenAPI (3.1) docs from structs (no comments or files needed)
  • Automatic parsing of JSON/text/binary/form requests
  • Automatic serialization of JSON/text/binary responses
  • Automatic handling of request/response parameters (cookies/query/headers/path)
  • Middleware (with easy error handling)
  • Route groups (with isolated middleware)
  • Error handling as responses
  • Static file serving from directories

An example of how some of this might look in practice is:

package main

import "github.com/matt1484/chimera"

type TestBody struct {
    Property string `json:"prop"`
}

type TestParams struct {
    Path string   `param:"path,in=path"`
    Header string `param:"header,in=header"`
}

func main() {
    api := chimera.NewAPI()
    api.Use(func(req *http.Request, ctx chimera.RouteContext, next chimera.NextFunc) (chimera.ResponseWriter, error) {
        resp, err := next(req)
        return resp, err
    })
    chimera.Get(api, "/test/{path}", func(req *chimera.JSON[TestBody, TestParams]) (*chimera.JSON[TestBody, chimera.Nil], error) {
        return &chimera.JSON[TestBody, TestParams]{
            Body: req.Body,
        }, nil
    })
    api.Start(":8000")
}

By using struct tags, generics, reflection, and carefully designed interfaces chimera can infer and automate a lot of the typical tasks that go developers often manually do.

This library relies heavily on chi to support the routing/grouping/middleware internally. While chi is all about being inline with the standard library, this library is more opinionated and instead goes for a more standard layout of development interfaces as seen in other languages/frameworks to support quicker development. A lof of its design was actually heavily inspired by fastapi and you can even see the parallels in this example here:

from typing import Annotated
from fastapi import FastAPI, Header
from pydantic import BaseModel

class TestBody(BaseModel):
    prop: str

api = fastapi.FastAPI()

@api.middleware("http")
def add_process_time_header(request: Request, next):
    response = next(request)
    return response

@api.get("/test/{path}")
def test(path: str, header: Annotated[str, Header()] = None, body: TestBody) -> TestBody
    return body

Docs

There are docs on github pages hosted here

TODO

  • Proper XML support
  • Multipart form support

chimera's People

Contributors

matt1484 avatar

Stargazers

卜木 avatar Gopinath avatar Michael Plunkett avatar  avatar linuxct avatar Jimmy Nelle avatar  avatar Adolfo Cia avatar Luis Alicea avatar Martin Soria Røvang avatar  avatar libchaos avatar Serge Kovalenko avatar Luke Kalbfleisch avatar  avatar SYM avatar Yoan Blanc avatar banshan avatar  avatar Arman Ordookhani avatar Vlad avatar  avatar Adam Zell avatar Ian avatar Dustin Farist avatar Benjamin Edwards avatar David Mair Spiess avatar Aleksander Birkeland avatar Tim Kersey avatar Johnny Steenbergen avatar  avatar Alexey Yurchenko avatar Andreas Karg avatar Vincent Serpoul avatar Jason Baker avatar Alex Goodman avatar Abdulhafiz KAŞGARLI avatar Scott Tiger avatar Spark avatar George Dobrovolsky avatar Andrei Surugiu avatar  avatar Hristo Karchokov avatar Zate avatar  avatar  avatar Vlad Oros avatar Abdullah Alattar avatar John Clayton avatar Jevgeni Sillar avatar Vorticalbox avatar Andriy Romanov avatar  avatar Joey Drew avatar Brad Lugo avatar

Watchers

 avatar  avatar

Forkers

zate thomastthai

chimera's Issues

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.