Skip to content

Get Started ๐Ÿ‘จโ€๐Ÿ’ป

๐Ÿ‘‹ Welcome to Fast Mocker! This guide will walk you through the steps to install, run, and test the Fast Mocker project. Fast Mocker is a Python 3.11 project using FastAPI to simulate a REST API, returning responses based on YAML files in the /mocks folder.

Installation ๐Ÿš€

Clone the Repository ๐Ÿ”—

To get started, you need to clone the Fast Mocker repository from GitHub. Open your terminal and run the following command:

git clone https://github.com/flaviofilipe/fast-mocker.git

Install Dependencies with Poetry ๐Ÿ“ฆ

Fast Mocker uses Poetry to manage its dependencies. If you don't have Poetry installed, you can install it using pip:

pip install poetry

Next, navigate to the project folder and use Poetry to install the required dependencies:

cd fast-mocker
poetry install

Running the Project โ–ถ๏ธ

Now that the project is installed, you can run Fast Mocker using the following command:

poetry run task run

Fast Mocker will now be running on localhost:8000 ๐ŸŒ. You can access the API endpoints at localhost:8000/{endpoint_path}.

YAML Configuration Files ๐Ÿ“„

Before testing the API, you need to create your YAML configuration files in the /mocks folder. The YAML files should follow the same structure as the example files: /mocks/animals.example.yml and /mocks/users.example.yml.

Example YAML Configuration โœ๏ธ

Here's an example of the YAML configuration format:

Animals:
  GetAnimals:
    path: /animals
    method: get
    response:
      media_type: application/json
      status_code: 200
      content: Hello World

  PostAnimals:
    path: /animals
    method: post
    response:
      media_type: application/json
      status_code: 201

Information โ„น๏ธ

  • Animals: Entity (replace with your desired entity name).
  • [GetAnimals, PostAnimals]: Templates (replace with your desired endpoint names).
  • path: The endpoint that can be accessed with localhost:8000/path.
  • method: The HTTP method to use when making a request to the path.
  • response: The response that will be returned when calling the endpoint.
  • media_type: The type of the response.
  • status_code: The HTTP status code of the response.

Testing with cURL ๐Ÿงช

After configuring the YAML files, you can test the API using cURL. For example:

curl -X GET http://localhost:8000/animals

Conclusion ๐ŸŽ‰

You've now successfully installed, run, and tested Fast Mocker! Feel free to explore the project, create more YAML configurations, and simulate various API responses.

If you have any questions or encounter any issues, don't hesitate to reach out for help. Happy mocking! ๐Ÿ˜„๐Ÿš€