Code Monkey home page Code Monkey logo

specmatic-order-bff-python-sanic's Introduction

Specmatic Sample: Python-Sanic BFF

This example project illustrates the practice of contract-driven development and contract testing within a Sanic (Python) application that relies on an external domain service. In this context, Specmatic is utilized to stub calls to domain API services according to its OpenAPI specification.

Here is the Domain OpenAPI spec

Here is the BFF OpenAPI spec

Definitions

  • BFF: Backend for Frontend
  • Domain API: API managing the domain model
  • Specmatic Stub/Mock Server: Generate a server that simulates a real service using its OpenAPI or AsyncAPI specification

Background

A standard web application setup may resemble the following structure. By leveraging Specmatic, we can engage in contract-driven development and perform comprehensive testing on all the components listed below. In this illustrative project, we demonstrate the process for a Sanic BFF, which relies on the Domain API Service, showcasing OpenAPI support within Specmatic.

HTML client talks to client API which talks to backend API

Tech

  1. Sanic
  2. Specmatic
  3. PyTest
  4. Coverage

Setup

  1. Install Python 3.12
  2. Install JRE 17 or later.

Setup Virtual Environment

  1. Create a virtual environment named ".venv" by executing the following command in the terminal from the project's root directory

     python -m venv .venv
  2. Activate virtual environment by executing

  • on MacOS and Linux

    source .venv/bin/activate
  • on Windows CMD

    .venv\Scripts\activate.bat
  • on Windows Powershell (you may need to adjust the ExecutionPolicy)

    .\.venv\Scripts\Activate.ps1

Install Dependencies

To install all necessary dependencies for this project, navigate to the project's root directory in your terminal and execute

pip install -r requirements.txt

Execute Tests and Validate Contracts with Specmatic

Executing this command will initiate Specmatic and execute the tests on the Sanic application.

pytest test -v -s

specmatic-order-bff-python-sanic's People

Contributors

jaydeepk avatar starkhan6368 avatar burdeamit avatar dependabot[bot] avatar

Watchers

Saurabh Nanda avatar HariKrishnan avatar Anand Bagmar avatar Julian Harty avatar  avatar Shama Ugale avatar  avatar Harsh Joshi avatar  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.