Django Smithy

Contents:

Django Smithy

https://badge.fury.io/py/django-smithy.svg https://travis-ci.org/jamiecounsell/django-smithy.svg?branch=master https://codecov.io/gh/jamiecounsell/django-smithy/branch/master/graph/badge.svg

Craft HTTP requests in the Django Admin. Django Smithy is an HTTP Request templating system that allows developers to build systems to send abstract messages without additional development.

Documentation

The full documentation is at https://django-smithy.readthedocs.io.

Quickstart

Install Django Smithy:

pip install django-smithy

Then, create a request template to send:

https://user-images.githubusercontent.com/2321599/54481318-90a2ba80-4809-11e9-96ae-46be38ad65d3.png

Features

  • Design requests in the Django Admin panel
  • Send requests with whatever context you’d like
  • Use Django’s templating system everywhere
  • Define variables to be added to the context

Running Tests

Does the code actually work?

source <YOURVIRTUALENV>/bin/activate
(myenv) $ pip install tox
(myenv) $ tox

Credits

Tools used in rendering this package:

Installation

At the command line:

$ easy_install django-smithy

Or, using pip:

$ pip install django-smithy

Or, if you have virtualenvwrapper installed:

$ mkvirtualenv django-smithy
$ pip install django-smithy

Usage

Before sending requests, you must first create a blueprint. Request blueprints drive all the requests sent through Django Smithy.

Once a blueprint is created, you can call the send method and provide a dictionary of context. This context will be passed to all properties of the request and interpreted using Django’s template language.

Django template syntax is supported in pretty much everything, including the name and value of headers, cookies, and query parameters, as well as the request body and URL. This makes it easy to make dynamic requests that contain contextual data.

Variables are just static values that allow you to easily reuse or swap out data without needing to provide it in code. This is great for storing things like API keys, but it’s important to note the security impacts of this, as the API key will be visible in plain text to any user with access to this section of the Django Admin.

# Retrieve the blueprint
# (will change depending on your use case)
blueprint = RequestBlueprint.objects.first()

# Send the request and get the record
record = blueprint.send(context = {
    'something': 'some value',
    'more_stuff': 0
})

# Or get all records for that blueprint
RequestRecord.from_blueprint(blueprint)

Once sent, a request will generate a RequestRecord with details of the response. The RequestRecord can be used to determine if a request failed or not and handle appropriately.

History

0.1.0 (2019-03-16)

  • First release on PyPI. No tests are present, use at your own risk!

0.2.0 (2019-03-07)

  • Add support for x-www-form-urlencoded content
  • Improved JS for admin form
  • Auto-add content-type header
  • Added better HTTP request/response records.