Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/simonw/django-http-debug
Django app for creating endpoints that log incoming request and return mock data
https://github.com/simonw/django-http-debug
django
Last synced: about 15 hours ago
JSON representation
Django app for creating endpoints that log incoming request and return mock data
- Host: GitHub
- URL: https://github.com/simonw/django-http-debug
- Owner: simonw
- License: apache-2.0
- Created: 2024-08-07T18:04:19.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2024-08-08T16:45:38.000Z (5 months ago)
- Last Synced: 2024-10-18T07:53:53.905Z (3 months ago)
- Topics: django
- Language: Python
- Homepage:
- Size: 21.5 KB
- Stars: 49
- Watchers: 1
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# django-http-debug
[![PyPI](https://img.shields.io/pypi/v/django-http-debug.svg)](https://pypi.org/project/django-http-debug/)
[![Tests](https://github.com/simonw/django-http-debug/actions/workflows/test.yml/badge.svg)](https://github.com/simonw/django-http-debug/actions/workflows/test.yml)
[![Changelog](https://img.shields.io/github/v/release/simonw/django-http-debug?include_prereleases&label=changelog)](https://github.com/simonw/django-http-debug/releases)
[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/simonw/django-http-debug/blob/main/LICENSE)Django app for creating database-backed HTTP debug endpoints
Background on this project: [django-http-debug, a new Django app mostly written by Claude](https://simonwillison.net/2024/Aug/8/django-http-debug/)
## Installation
Install this library using `pip`:
```bash
pip install django-http-debug
```
## ConfigurationOnce installed in the same environment as your Django application, add the following to `INSTALLED_APPS` in your Django settings:
```python
INSTALLED_APPS = [
# ...
'django_http_debug',
# ...
]
```
And add this to `MIDDLEWARE`:
```python
MIDDLEWARE = [
# ...
"django_http_debug.middleware.DebugMiddleware",
# ...
]
```
Then run `./manage.py migrate` to create the necessary database tables.## Usage
You can configure new endpoints in the Django admin. These will only work if they are for URLs that are not yet being served by the rest of your application.
Give an endpoint a path (starting without a `/`) such as:
webhooks/debug/
You can optionally configure the returned body or HTTP headers here too.
If you want to return a binary body - a GIF for example - you can set that endpoint to use Base64 encoding and then paste a base64-encoded string into the body field.
On macOS you can create base64 strings like this:
```bash
base64 -i pixel.gif -o -
```
Any HTTP requests made to `/webhooks/debug/` will be logged in the database. You can view these requests in the Django admin.You can turn off the "Logging enabled" option on an endpoint to stop logging requests to it to the database.
## Development
To contribute to this library, first checkout the code. Then create a new virtual environment:
```bash
cd django-http-debug
python -m venv venv
source venv/bin/activate
```
Now install the dependencies and test dependencies:
```bash
pip install -e '.[test]'
```
To run the tests:
```bash
pytest
```