Git Product home page Git Product logo

simple-testing-server's Introduction

simple-testing-server

A stupidly simple python server that allows you to test client code before you have a server that actually works Allows you to test json responses with the proper headers built in, and also custom error codes.

Motivation

So say you want to build some sort of app that connects to a client... great! But how are you going to deal with separating the development between the application logic and the backend api? Where are your api calls supposed to go before that server exists? Enter this project.

Example Usage

Start by spinning up the server using

python simple-testing-server.py --port <PORT>

GET

This server uses json as the default object structe. Say you want to get an example json response from your server. Suppose you're modeling some data in your app. Let's call an example model events. Then

GET http://localhost:<PORT>/events

will return to you the contents of a file called events.json with proper headers. This file is up to you to create and place in the same folder as the python script.

More generally, GET http://localhost:<PORT>/<model_name> will return an application/json response with content taken from a file called <model_name>.json placed in the same folder as the script. BYO example json files. (use the --path options if these files are in a different directory)

POST

To make a post request with a successfull (200) response:

POST http://localhost:<PORT>/success

Want a failure (500)? Try

POST http://localhost:<PORT>/error

Those two response codes aren't good enough for you? Fine.

POST http://localhost:<PORT>/<response_code>

The body accepts parameters in application/x-www-form-urlencoded format.

Set Content-Type to application/x-www-form-urlencoded

POST http://localhost:<PORT>/any_url
p1=v1&p2=v2&p3=v3

The result is parsed and returned back as JSON

{
   "p2":"v2",
   "p3":"v3",
   "p1":"v1"
}

There you have it.

Options

A list of command line options:

  • -h, --help - show a help message
  • -p <PORT>, --port <PORT> - run on a custom port
  • --path <PATH> - keep your sample data in a custom path

Compatibility

AFAIK all versions of python. If you don't have argparse installed, the custom port won't work and it will just default to PORT=8003 every time.

Authors

License

This program is free software. It comes without any warranty, to the extent permitted by applicable law. You can redistribute it and/or modify it under the terms of the WTFPL, Version 2, as published by Sam Hocevar. See http://sam.zoy.org/wtfpl/ for more details.

simple-testing-server's People

Contributors

mathisonian avatar rfdy avatar asandwhich avatar

Watchers

James Cloos avatar Basit Anwer avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.