Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.
/ hugpee Public archive

HugPee simplifies the creation of RESTful CRUD endpoints in hug, for peewee models.

License

Notifications You must be signed in to change notification settings

kostasdizas/hugpee

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HugPee

HugPee simplifies the creation of RESTful CRUD endpoints in hug, for peewee models.

Installing HugPee

Installing Hugpee is very simple, just run:

pip3 install hugpee --upgrade

Usage

Consider a scenario where Person is our peewee model. Creating the CRUD endpoints for hug is very simple with HugPee:

hugpee.HugPee(Person)

And then load them to hug.

@hug.extend_api()
def get_all_hugs():
    return [modelendpoint]

Here is the full working example:

import hug
from peewee import SqliteDatabase, Model
from peewee import PrimaryKeyField, CharField, DateField, BooleanField
import hugpee

db = SqliteDatabase(":memory:")

class Person(Model):
    ID = PrimaryKeyField()
    name = CharField()
    birthday = DateField()
    is_relative = BooleanField()
    class Meta:
        database = db

db.create_tables([Person])

hugpee.HugPee(Person)

@hug.extend_api()
def get_all_hugs():
    return [hugpee]

This will create the following endpoints:

HTTP ACTION URI(s) Accepted Parameters
POST /person name, birthday, is_relative
GET /person , /person/{id} id
PUT /person , /person/{id} id, name, birthday, is_relative
DELETE /person , /person/{id} id

Note that the primary key, in this case the id, can be provided either as part of the URI or as a parameter.

About

HugPee simplifies the creation of RESTful CRUD endpoints in hug, for peewee models.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages