https://github.com/alexliubj/smoke-framework-example
How to make a simple Post request with Smoke-Framework
https://github.com/alexliubj/smoke-framework-example
amazon-smoke-framework ios restful-api serverside-swift swift
Last synced: 3 months ago
JSON representation
How to make a simple Post request with Smoke-Framework
- Host: GitHub
- URL: https://github.com/alexliubj/smoke-framework-example
- Owner: alexliubj
- License: mit
- Created: 2019-02-12T21:51:54.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-02-12T21:57:50.000Z (over 6 years ago)
- Last Synced: 2025-01-19T10:42:58.625Z (5 months ago)
- Topics: amazon-smoke-framework, ios, restful-api, serverside-swift, swift
- Language: Swift
- Homepage:
- Size: 101 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## 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:
```swift
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