tdyn / flask-echo-server

Tiny Flask app for testing HTTP calls

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Flask Echo Server

License: MIT Code style: black

A simple Flask application that can be used to test HTTP calls. It simply logs out the request and request data then returns an object with the request information. Useful for debugging HTTP calls to third-party APIs by making the same calls to this server or developing applications locally when you don't want to call real API endpoints.

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development.

Prerequisites

Install Dependencies

First, install dependencies:

$ pipenv install
Creating a virtualenv for this project…
...
Virtualenv location: /Users/user/.virtualenvs/flask-echo-server-zyMB51yv
Installing dependencies from Pipfile.lock (8a3288)…
  🐍   β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰ 6/6 β€” 00:00:04
To activate this project's virtualenv, run the following:
 $ pipenv shell

Activate the virtual environment:

$ pipenv shell
Spawning environment shell (/bin/zsh). Use 'exit' to leave.
(flask-echo-server-zyMB51yv) $

Start the Application

Run the application:

$ export FLASK_ENV=development; flask run
 * Environment: development
 * Debug mode: on
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: XXX-XXX-XXX

Usage

Example: POST JSON

$ curl -d '{"key1":"value1", "key2":"value2"}' -H "Content-Type: application/json" -X POST 127.0.0.1:5000/api/v1/test
{
  "data": "{\"key1\":\"value1\", \"key2\":\"value2\"}",
  "endpoint": "api/v1/test",
  "form": {},
  "json": {
    "key1": "value1",
    "key2": "value2"
  }
}

Server log:

*** Received data at: api/v1/test
data b'{"key1":"value1", "key2":"value2"}'
form ImmutableMultiDict([])
json {'key1': 'value1', 'key2': 'value2'}

Example: POST Form Data

$ curl -d "param1=value1&param2=value2" -X POST 127.0.0.1:5000/api/v1/test
{
  "data": "",
  "endpoint": "api/v1/test",
  "form": {
    "param1": "value1",
    "param2": "value2"
  },
  "json": null
}

Server log:

*** Received data at: api/v1/test
data b''
form ImmutableMultiDict([('param1', 'value1'), ('param2', 'value2')])
json None

Built With

Contributing

Please read CONTRIBUTING.md for details on our code of conduct.

Authors

License

This project is licensed under the MIT License - see the LICENSE file for details.

Wanna Cuttle?

About

Tiny Flask app for testing HTTP calls

License:MIT License


Languages

Language:Python 100.0%