<commit_before>* api-hi

A lib to api-fy things (ORMs models) using some other things (web frameworks)

In the end it should not be tied to one specific ORM or framework.

It is not made for complicated APIs, only two 'levels' on the API:
- / and /<id>

If there is any relation to go through, we can iterate over their ID
and query the right API path

use a decorator from an authentication library (ie: bottle-cork)

More to come:
- PUT, DELETE
- Flask, SQLAlchemy
- Documentation

Hopefully?:
- Mongo, Riak
- Ansible?
- IMAP?

** Install
   #+BEGIN_SRC sh
     pip install -e https://github.com/abondis/api-hi/archive/master.zip
   #+END_SRC

** Example
*** Setup models using the desired (supported) ORM
    for example peewee (more coming)
    #+BEGIN_SRC python
      class Post(Model):
          #put fields
          pass
      
      class File(Model):
          #put fields
          #and foreign key to Post id
          pass
    #+END_SRC
  
*** Setup the authentication decorator
    for example bottle-cork
    #+BEGIN_SRC python
      aaa = Cork('auth_files')
      api_auth = aaa.make_auth_decorator(
          fail_redirect="/login", role="read")
    #+END_SRC

*** Setup a web framework app
    #+BEGIN_SRC python
      app = bottle.default_app()
    #+END_SRC

*** Api-fy the model
     - GET is the default method allowed
     - pass the decorator the same way it would be used on a routed function
     - Post and File are just the class
     - app is an instance of the web application

**** Get a list of posts
     #+BEGIN_SRC python
       apify('/api/posts', Post, app, auth=api_auth())
     #+END_SRC
**** Get a list of files
     #+BEGIN_SRC python
       apify('/api/files', File, app, auth=api_auth())
     #+END_SRC
**** Create a post
     - allow POST method to an 'admin'
     - this will only map to `/api/posts` since it is only used to create an item
     #+BEGIN_SRC python
       apify('/api/posts', Post, app, methods=['POST'], auth=api_auth('admin'))
     #+END_SRC<commit_msg>readme bis<commit_after>* api-hi

A lib to api-fy things (ORMs models) using some other things (web frameworks)

In the end it should not be tied to one specific ORM or framework.

It is not made for complicated APIs, only two 'levels' on the API:
- / and /<id>

If there is any relation to go through, we can iterate over their ID
and query the right API path

use a decorator from an authentication library (ie: bottle-cork)

More to come:
- PUT, DELETE
- Flask, SQLAlchemy
- Documentation

Hopefully?:
- Mongo, Riak
- Ansible?
- IMAP?

** Install
   #+BEGIN_SRC sh
     pip install -e https://github.com/abondis/api-hi/archive/master.zip
   #+END_SRC

** Example
*** Setup models using the desired (supported) ORM
    for example peewee (more coming)
    #+BEGIN_SRC python
      class Post(Model):
          #put fields
          pass
      
      class File(Model):
          #put fields
          #and foreign key to Post id
          pass
    #+END_SRC
  
*** Setup the authentication decorator
    for example bottle-cork
    #+BEGIN_SRC python
      aaa = Cork('auth_files')
      api_auth = aaa.make_auth_decorator(
          fail_redirect="/login", role="read")
    #+END_SRC

*** Setup a web framework app
    #+BEGIN_SRC python
      app = bottle.default_app()
    #+END_SRC

*** Api-fy the model
     - GET is the default method allowed
     - pass the decorator the same way it would be used on a routed function
     - Post and File are just the class
     - app is an instance of the web application

**** Get a list of posts
     #+BEGIN_SRC python
       api_hi('/api/posts', Post, app, auth=api_auth())
     #+END_SRC
**** Get a list of files
     #+BEGIN_SRC python
       api_hi('/api/files', File, app, auth=api_auth())
     #+END_SRC
**** Create a post
     - allow POST method to an 'admin'
     - this will only map to `/api/posts` since it is only used to create an item
     #+BEGIN_SRC python
       api_hi('/api/posts', Post, app, methods=['POST'], auth=api_auth('admin'))
     #+END_SRC
{'fraction_non_alphanumeric': 0.09816559246405553, 'fraction_numerical': 0.0, 'mean_word_length': 2.668181818181818, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4167728', 'n_tokens_mistral': 1280, 'n_tokens_neox': 1241, 'n_words': 492}