{ "info": { "author": "Jonathan Moss", "author_email": "jmoss@commoncode.io", "bugtrack_url": null, "classifiers": [ "Intended Audience :: Developers", "Programming Language :: Python :: 3.6", "Topic :: Utilities" ], "description": "Baked Beans\n===========\n\n.. image:: https://travis-ci.org/a-musing-moose/bakedbeans.svg?branch=master\n :target: https://travis-ci.org/a-musing-moose/bakedbeans\n\nBaked Beans is a terribly named HTTP stub server for REST services that deal in JSON payloads written in Python but easily runnable as a Docker container.\n\nIt takes a super simple approach of using a folder of contents that provide the canned responses it produces.\n\ne.g ``GET http://localhost:3000/path/to/some/resource`` would map to the file: ``/path/to/some/resource.get.json``.\n\nNote in the example above that the file name looked for includes the HTTP method used.\n\nIn it's basic mode, Baked Beans will simply load the matching file and pipe it back to the client.\n\nIt also supports a limited amount of smarts. JSON file constructed to a specific schema can be used by Baked Beans to return specific responses. For example, it can match responses based on GET parameters.\n\n\nInstallation\n------------\n\nCreate a python virtual environment with your favourite tools. Then use pip to install ``bakedbeans``:\n\n.. code-block:: bash\n\n (venv) $ pip install bakedbeans\n\n\nRunning\n-------\n\nBaked Beans provides a simple command line executable to run the server:\n\n.. code-block:: bash\n\n (venv) $ baked /path/to/contents/folder\n * Running on http://127.0.0.1:3000/ (Press CTRL+C to quit)\n\n\nYou can specify the host name with ``--host`` and the port it binds to with ``--port``.\n\nBaked Beans is also built with Docker in mind. To run Baked Beans in docker you will need to mount your local contents directory as a volume. For example:\n\n.. code-block:: bash\n\n docker run -it --rm -p 3000:3000 -v /full/path/to/contents:/contents moose/bakedbeans\n\nThis will run Baked Beans in a container that will remove itself once exit, mounting the ``/full/path/to/contents`` inside the container at ``/contents`` which is where Baked Beans is configured to load the contents from.\n\nWriting contents\n-----------------\n\nBaked Beans maps URLs to file paths, adding ``..json`` to the end of the path. There are a couple of exceptions, for example if the URL ends with ``/`` it will instead add ``index..json``.\n\nExamples:\n\n +-------------------------------------+--------------------------------+\n | Request URL | Mapped Path |\n +=====================================+================================+\n | GET http://localhost:3000/somewhere | ``/somewhere.get.json`` |\n +-------------------------------------+--------------------------------+\n | POST http://localhost:3000/another | ``/another.post.json`` |\n +-------------------------------------+--------------------------------+\n | GET http://localhost:3000/ | ``/index.get.json`` |\n +-------------------------------------+--------------------------------+\n\nBy default the contents of the file once loaded to feed back to the request verbatim.\n\nHowever, if you want to get clever with the response you can write the JSON file in the ``bean`` format. ``Beans`` are just something I made up for this project and take the form of a JSON object. For example:\n\n\n.. code-block:: javascript\n\n {\n \"_bean\": true,\n \"responses\": [\n {\n \"params\": {\n \"product\": \"1111\"\n },\n \"contents\": {\n \"id\": 1111,\n \"name\": \"Product A\"\n }\n },\n {\n \"params\": {\n \"product\": \"2222\"\n },\n \"status\": 203,\n \"contents\": {\n \"id\": 2222,\n \"name\": \"Product B\"\n }\n }\n\n\n ]\n\n }\n\n\nWith the ``bean`` above, it is matching the response based on the GET parameters that accompany the request. e.g. ``http://localhost:3000/path?product=1111`` would match the first response and return the value of ``contents``. A GET param of ``product=2222`` would match the second. If no match is found, then the first one is selected regardless.\n\nNote also that the second response specifies a ``status``, this allow you to specify a specific status code to use for the response. If not specified then a default value based on the HTTP method is used.\n\nThe default status codes are:\n\n+---------+------+\n| Method | Code |\n+=========+======+\n| GET | 200 |\n+---------+------+\n| POST | 201 |\n+---------+------+\n| DELETE | 204 |\n+---------+------+\n| PUT | 200 |\n+---------+------+\n| PATCH | 200 |\n+---------+------+\n| | 200 |\n+---------+------+\n\nCurrently only GET parameter matching is supported but header and body matching would be a nice addition as would regex of values and use of matched criteria within the content...\n\n\nHits & Misses\n-------------\n\nThe above describes have things work if everything is perfect. The url matches a content file, the content file is valid JSON, and if needed a valid ``bean``. But what happens when things don't match up:\n\nContent not found\n ``404`` status with a body of ``{\"error\": \"content not found the/missing/path\"}``\n\nInvalid content file\n ``500`` status with a body of ``{\"error\": \"content invalid\"}``\n\nBean fails validation\n ``500`` status with a body of ``{\"error\": \"This is one mouldy bean\"}``\n\n\nMore detailed descriptions of the error encountered can be found in the logs.", "description_content_type": null, "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/a-musing-moose/bakedbeans", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "bakedbeans", "package_url": "https://pypi.org/project/bakedbeans/", "platform": "", "project_url": "https://pypi.org/project/bakedbeans/", "project_urls": { "Homepage": "https://github.com/a-musing-moose/bakedbeans" }, "release_url": "https://pypi.org/project/bakedbeans/0.1.4/", "requires_dist": null, "requires_python": "", "summary": "Canned response HTTP server", "version": "0.1.4" }, "last_serial": 3518579, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "b90e41de0b1e5536bfc6881649ab9779", "sha256": "4eb0c75c56bde469de9513c9db11f299804eb027bc1099a528d28887fb9c5a43" }, "downloads": -1, "filename": "bakedbeans-0.1.tar.gz", "has_sig": false, "md5_digest": "b90e41de0b1e5536bfc6881649ab9779", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4903, "upload_time": "2018-01-11T06:13:50", "url": "https://files.pythonhosted.org/packages/ae/76/5696d205d11c18f3345d0ba1a08841f4e50c7c1a7d0772a8b0b39e2c59e3/bakedbeans-0.1.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "28c1c485b4b6d553e561712d634545f6", "sha256": "baa3aebdcda44c2ccb1a0e5caaa3cc93a1e6a762873dea1cb3100b18d98f960b" }, "downloads": -1, "filename": "bakedbeans-0.1.1.tar.gz", "has_sig": false, "md5_digest": "28c1c485b4b6d553e561712d634545f6", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6403, "upload_time": "2018-01-11T06:26:53", "url": "https://files.pythonhosted.org/packages/db/43/2c801e70ad10ce1c503ed59b0df6418ca59caba125ed551f01fd47829652/bakedbeans-0.1.1.tar.gz" } ], "0.1.2": [ { "comment_text": "", "digests": { "md5": "a88c8c2aff2790d3825604ca2dca7996", "sha256": "7a1c6423fac8a352bacb9c1aae70e8379deac7fd16016f01df0ca19a0d218479" }, "downloads": -1, "filename": "bakedbeans-0.1.2.tar.gz", "has_sig": false, "md5_digest": "a88c8c2aff2790d3825604ca2dca7996", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6401, "upload_time": "2018-01-11T06:38:32", "url": "https://files.pythonhosted.org/packages/e6/2d/b9321bbb955dcea377223b7bdfdce8239bb5fa0de20a9cef2a955c141bdc/bakedbeans-0.1.2.tar.gz" } ], "0.1.3": [ { "comment_text": "", "digests": { "md5": "3da1817dd04cd0a6c7eb4231afae2732", "sha256": "83d40e9a074594ebcc5b43eb771d567ec42043bcb6712e2acd204648c94c919b" }, "downloads": -1, "filename": "bakedbeans-0.1.3.tar.gz", "has_sig": false, "md5_digest": "3da1817dd04cd0a6c7eb4231afae2732", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6445, "upload_time": "2018-01-17T21:03:04", "url": "https://files.pythonhosted.org/packages/f0/30/368ee6054cfde1523b41e17bb7df6a4413ca12afbeb5deb701657d1df779/bakedbeans-0.1.3.tar.gz" } ], "0.1.4": [ { "comment_text": "", "digests": { "md5": "455aa338ca12262ce60960b3d88ea033", "sha256": "68317c349c136c778dca0443b674ada73e77e484bc0e81794821603c7f0bf6f5" }, "downloads": -1, "filename": "bakedbeans-0.1.4.tar.gz", "has_sig": false, "md5_digest": "455aa338ca12262ce60960b3d88ea033", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6489, "upload_time": "2018-01-24T21:59:40", "url": "https://files.pythonhosted.org/packages/50/56/621e5115ae58ea461f1b66ee62ba75b6a7bfa1c3ded478760ef78ac40525/bakedbeans-0.1.4.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "455aa338ca12262ce60960b3d88ea033", "sha256": "68317c349c136c778dca0443b674ada73e77e484bc0e81794821603c7f0bf6f5" }, "downloads": -1, "filename": "bakedbeans-0.1.4.tar.gz", "has_sig": false, "md5_digest": "455aa338ca12262ce60960b3d88ea033", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6489, "upload_time": "2018-01-24T21:59:40", "url": "https://files.pythonhosted.org/packages/50/56/621e5115ae58ea461f1b66ee62ba75b6a7bfa1c3ded478760ef78ac40525/bakedbeans-0.1.4.tar.gz" } ] }