
Security News
NVD Quietly Sweeps 100K+ CVEs Into a “Deferred” Black Hole
NVD now marks all pre-2018 CVEs as "Deferred," signaling it will no longer enrich older vulnerabilities, further eroding trust in its data.
hapic is a framework-agnostic library for coding professionnal REST APIs.
hapic as been developed by algoo in the context of a large service oriented project. The lack of a tool allowing real auto-documentation of Rest API has decided us to develop hapic.
target usage is not for "quick and dirty" stuff but for professionnal, maintainable, long-term targeted projects.
The separation of concerns between REST APIs layer and business stuff layer is in the DNA of hapic.
hapic is just the HTTP layer glue code over your business code.
When you decide to base your development on hapic, you'll get direct benefits:
hapic is licenced under the MIT licence. You can use it in your projects, closed or open sourced.
hapic source code is ready for production. Some refactoring are identified and required for maintainability, but public APIs are stable so you can rely on hapic for your developments.
hapic is under active development, based on different professional projects. we will answer your questions and accept merge requests if you find bugs or want to include features.
hapic is automatically tested on python 3.5, 3.6 and 3.7
TODOs in the code can include some #xxx
- these are github issues references.
For better performances with yaml module, you can install following (debian instruction):
sudo apt-get install libyaml-dev
libyaml-dev
package can be removed after hapic install.
virtualenv -p /usr/bin/python3 venv
source venv/bin/activate
python setup.py develop
To work with Marshmallow schemas, install necessary dependencies:
pip install -e ".[marshmallow]"
To work with Serpyco dataclasses, install necessary dependencies:
pip install -e ".[serpyco]"
To have full environment (for developpers):
pip install -e ".[dev"]
To work with Marshmallow schemas, install necessary dependencies:
pip install hapic[marshmallow]
To work with Serpyco dataclasses, install necessary dependencies:
pip install hapic[serpyco]
from datetime import datetime
import flask
import marshmallow
import hapic
from hapic.ext.flask import FlaskContext
import json
hapic = hapic.Hapic()
app = flask.Flask(__name__)
class UriPathSchema(marshmallow.Schema): # schema describing the URI and allowed values
name = marshmallow.fields.String(required=True)
age = marshmallow.fields.Integer(required=False)
class HelloResponseSchema(marshmallow.Schema): # schema of the API response
name = marshmallow.fields.String(required=True)
now = marshmallow.fields.DateTime(required=False)
greetings = marshmallow.fields.String(required=False)
@app.route('/hello/<name>') # flask route. must always be before hapic decorators
@hapic.with_api_doc() # the first hapic decorator. Register the method for auto-documentation
@hapic.input_path(UriPathSchema()) # validate the URI structure
@hapic.output_body(HelloResponseSchema()) # define output structure
def hello(name='<No name>', hapic_data=None):
return {
'name': name,
'now': datetime.now(),
'dummy': { 'some': 'dummy' } # will be ignored
}
class UriPathSchemaWithAge(marshmallow.Schema): # schema describing the URI and allowed values
name = marshmallow.fields.String(required=True)
age = marshmallow.fields.Integer(required=False)
@app.route('/hello/<name>/age/<age>')
@hapic.with_api_doc()
@hapic.input_path(UriPathSchemaWithAge())
@hapic.output_body(HelloResponseSchema())
def hello2(name='<No name>', age=42, hapic_data=None):
return {
'name': name,
'age': age,
'greetings': 'Hello {name}, it looks like you are {age}'.format(
name=name,
age=age
),
'now': datetime.now(),
'dummy': { 'some': 'dummy' } # will be ignored
}
hapic.set_context(FlaskContext(app))
print(json.dumps(hapic.generate_doc(title='API Doc', description='doc desc.'))) # Generate the documentation
app.run('127.0.0.1', 8080, debug=True)
How to use it:
Nominal cases:
$ curl "http://127.0.0.1:8080/hello/michel"
# {"now": "2017-12-18T12:37:10.751623+00:00", "name": "michel"}
$ curl "http://127.0.0.1:8080/hello/michel/age/17"
# {"name": "damien", "greetings": "Hello damien, it looks like you are 17", "now": "2017-12-18T12:41:58.229679+00:00"}
Error case (returns a 400):
$ curl "http://127.0.0.1:8080/hello/michel/age/mistaken"
# {"details": {"age": ["Not a valid integer."]}, "message": "Validation error of input data"}
In the example/usermanagement
directory you can find a complete example of an API allowing to manage users.
Features are:
In order to test it :
Install the required dependencies:
pip install bottle flask pyramid`
Run the instance you wan to test (one of the three following lines):
python example/usermanagement/serve_bottle.py
python example/usermanagement/serve_flask.py
python example/usermanagement/serve_pyramid.py
Features shown :
FAQs
HTTP api input/output manager
We found that hapic demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
NVD now marks all pre-2018 CVEs as "Deferred," signaling it will no longer enrich older vulnerabilities, further eroding trust in its data.
Research
Security News
Lazarus-linked threat actors expand their npm malware campaign with new RAT loaders, hex obfuscation, and over 5,600 downloads across 11 packages.
Security News
Safari 18.4 adds support for Iterator Helpers and two other TC39 JavaScript features, bringing full cross-browser coverage to key parts of the ECMAScript spec.