Categorygithub.com/glothriel/grf
module
1.0.0
Repository: https://github.com/glothriel/grf.git
Documentation: pkg.go.dev

# README

Gin rest framework

codecov slack

A REST framework for golang, highly inspired by Django REST framework. Main goal of this project is to achieve ease of implementing REST services similar to DRF with similar APIs but with better performance.

DRF comparison

Feature - wise

GRF is way simpler than DRF, mostly because it misses the "D" part - it doesn't have django, so all the goodies coming with Django won't be available. It also is quite fresh project and it doesn't support a lot of stuff DRF has, mainly:

  • authentication and authorization (you can write some ie. JWT validating middleware, but no built in support)
  • non-JSON responses
  • HTML views
  • Django admin - like UI

Performance

TLDR for the results: GRF is able to withstand 4x more reqps than the best DRF scenario, while using 2x less CPU, 10x less Memory, 4x smaller docker image, and having roughly the same latency.

The benchmark was performed using the following scenario:

  • Single model and ModelViewset in DRF / ModelView in GRF (pkg/examples/products.go)
  • Local sqlite database saved in /tmp
  • Perform load test by spamming list endpoint with 3 products (k6/test.js)
  • Docker image based on alpine (GRF, glibc is required for sqlite) and distroless (DRF) started with docker run
  • A single Standard_D4_v3 (4CPUs 16GB mem) Azure VM used
  • k6 was launched on the same machine with --vus 10 --duration 60s for each scenario
scenarioavg reqpslatency p(90)latency p(95)avg number of cores usedused memorydocker image size
GRF ModelListCreateView4067.9839364.6399166.53156441.68636521718.330MB
DRF ModelViewset + gunicorn --worker-class=gevent --workers 4 --threads 41091.5965244.46144076.094623.44176087176120MB
DRF ModelViewset + gunicorn --worker-class=gevent --workers 41065.3732944.4154794.7771433.436626087176.7120MB
DRF ModelViewset + gunicorn --workers 4 --threads 21025.5874416.32105518.607524253.348573913169.2120MB
DRF ModelViewset + gunicorn --workers 4 --threads 4983.651401416.25740419.100553253.371121739170.9120MB
DRF ModelViewset + gunicorn --workers 8 --threads 2969.266374119.2585823.32093363.489287.7120MB
DRF ModelViewset + gunicorn --worker-class=gevent --workers 8956.314210216.964931920.0199593.497873913321.5120MB
DRF ModelViewset + gunicorn --worker-class=gevent --workers 8 --threads 2939.644484117.175375220.09408223.502413043321.8120MB
DRF ModelViewset + gunicorn --worker-class=gevent --workers 2 --threads 8874.532025927.93499540.7662812.027017391102.6120MB
DRF ModelViewset + gunicorn --worker-class=gevent --workers 2859.672665828.63655541.543802552.020104348102.6120MB

Other gunicorn flag variants had even lower performance.

Roadmap

  • Add rich context to serializer and fields (ability to extract gin request data directly from Field)
    • Unlocks creating fields based on non-body data, gin context, etc - like CurrentlyLoggedInUser from Authorization header or so
  • Add support for setting up middleware (fore/after request is executed), including using Gin middlewares directly
  • Turn off passthrough if the serializer field type cannot be deduced on startup
  • Improve unit test coverage
  • Documentation portal
  • Add support for complex to implement types:
    • time.Time and sql.NullTime
    • time.Duration
    • list<int>
    • pointer fields, for example *string
    • sql.Null.* fields, for example sql.NullString
    • JSON fields, both as text (sqlite) and as dedicated columns (eg. Postgres)
  • Add support for partial update (PATCH)
  • SliceModelFields do not work with JSONSchemaValidator
  • Add support for model relations
  • Add support for viewsets
  • Add support for authentication
  • Add support for complex pagination implementations
  • Add support for permissions (authorization)
  • Add support for automatic OpenAPI spec generation
  • Add support for caches
  • Add support for throttling
  • Add support for output formatters
  • Add support for non-JSON types
  • Add support for translations (error messages)
  • Add validation of model field tags (consider changing json to custom grf, add warning for goplayground)
  • Improve performance with caching already allocated fields instead of using reflect.New
  • Add testing utils

# Packages

No description provided by the author