Code Monkey home page Code Monkey logo

smoke-framework-example's Introduction

How to make a simple Post request with Smoke-Framework

Start

First of all, open terminal and create a new empty folder.

Create an executable package by running the following commands in the terminal: swift package init --type executable

Open Package.swift file and add smoke-framework into dependencies section and also update targets dependencies:

let package = Package(
    name: "SmokeAPI",
    dependencies: [
        .package(url: "https://github.com/amzn/smoke-framework.git", .upToNextMajor(from: "0.6.0"))
    ],
    targets: [
        // Targets are the basic building blocks of a package. A target can define a module or a test suite.
        // Targets can depend on other targets in this package, and on products in packages which this package depends on.
        .target(
            name: "SmokeAPI",
            dependencies: ["SmokeOperations", "SmokeHTTP1"]),
        .testTarget(
            name: "SmokeAPITests",
            dependencies: ["SmokeAPI"]),
    ]
)

Build

Back to terminal and type swift build. This command will fetch Smoke-framework for you into this folder as well as those dependencies required by Smoke-framework.

You will see main.swift file locates in Sources/SmokeAPI and if you open it there will be only one line of code: print("Hello, world!")

In this example, there are a few files which are abstracted from test cases in Smoke-framework.

  • main sets up the post API and starts service
  • ExampleInput defines input data structure
  • ExampleError defines errors
  • ExampleOutput defines output structure

Run

Type swift run SmokeAPI in terminal to run main file and start service.

Test

You can either test it in your own project with HTTP request or test it with some tools like postman. Here's the screenshot of testing it with postman

Postman test result

smoke-framework-example's People

Contributors

alexliubj avatar

Stargazers

 avatar  avatar

Watchers

 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.