Skip to content

An example API testing project.

License

Apache-2.0, Unknown licenses found

Licenses found

Apache-2.0
LICENSE
Unknown
LICENSE.zh_CN
Notifications You must be signed in to change notification settings

PerfectExamples/API-Testing-Target

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

API Testing Target

Get Involed with Perfect!

Star Perfect On Github Stack Overflow Follow Perfect on Twitter Join the Perfect Slack

Swift 3.0 Platforms OS X | Linux License Apache PerfectlySoft Twitter Slack Status

API Testing Target Project

This repository is intended as a demonstration project for testing API's with Postman or Paw.

It provides a small range of API endpoints illustrating specific techniques.

Run in Postman

Compatibility with Swift

The master branch of this project currently compiles with Xcode 8.3 or the Swift 3.1 toolchain on Ubuntu.

Building & Running

The following will clone and build an empty starter project and launch the server on port 8181.

git clone https://github.com/PerfectExamples/API-Testing-Target.git
cd API-Testing-Target
swift build
.build/debug/APITestingTarget

You should see the following output:

[INFO] Starting HTTP server localhost on 0.0.0.0:8181

This means the server is running and waiting for connections. Access http://localhost:8181/ to see the greeting. Hit control-c to terminate the server.

Starter Content

List content:

routes.append(["method":"get", "uri":"/api/v1/test", "handler":Handlers.testGet])

Returns an array of users. Note the id is randomly generated at each executable launch.

{
  "result": [
    {
      "id": "0ED87700-16BA-4210-A8F7-5496EADAD224",
      "name": "Peter"
    },
    {
      "id": "6463DD8A-A3B9-4692-BE85-E0FC679396C0",
      "name": "Kirsty"
    },
    {
      "id": "06A3ADD7-470F-4818-891A-CE5BB120C63E",
      "name": "James"
    },
    {
      "id": "F71A0304-C1C8-45A3-8819-1CB81580A1DE",
      "name": "Anna"
    },
    {
      "id": "5344ACBC-07DD-430B-8D5C-1AFFBD2DA7B4",
      "name": "Sarah"
    }
  ]
}

Retrieve a specific entry

routes.append(["method":"get", "uri":"/api/v1/test/{id}", "handler":Handlers.testGet])

Returns JSON wil the details of the matching entry

{
  "result": {
    "id": "6463DD8A-A3B9-4692-BE85-E0FC679396C0",
    "name": "Kirsty"
  }
}

Submits a new record to be added to the array

routes.append(["method":"post", "uri":"/api/v1/test", "handler":Handlers.testPost])

Submitting with a payload of {"name":"David"} will return { "error": "none" }

Modify a record

routes.append(["method":"patch", "uri":"/api/v1/test/{id}", "handler":Handlers.testPatch])

Submit with a raw content body of {"name":"P3t3r"} and a matching {id} in the body to trigger an update.

Deletes a specific entry

routes.append(["method":"delete", "uri":"/api/v1/test/{id}", "handler":Handlers.testDelete])

Demonstrates the extraction of a header value from the request

routes.append(["method":"get", "uri":"/api/v1/testbearer", "handler":Handlers.testBearerToken])

In Postman (or equivalent), add a "Authorization" header parameter with a value of "Bearer {token}", where {token} is your bearer token value. The method in the API will extract the token and echo it back to you.

Bearer tokens are extensively used for JSON API authorizations.

Simple HTML

routes.append(["method":"get", "uri":"/", "handler":Handlers.stdHTML])

This API also contains some simple HTML to demonstrate previewing the raw source and rendered code within Postman or equivalent.

How this project was built

This project was built from a Swift scaffolding application, Clingon. The JSON used to create the starting point was this file, and then the business logic added. Clingon is free and open sourced just like Perfect.

Issues

We use JIRA for all bugs and support related issues.

If you find a mistake, bug, or any other helpful suggestion you'd like to make on the docs please head over to http://jira.perfect.org:8080/servicedesk/customer/portal/1 and raise it.

A comprehensive list of open issues can be found at http://jira.perfect.org:8080/projects/ISS/issues

Further Information

For more information on the Perfect project, please visit perfect.org.

About

An example API testing project.

Resources

License

Apache-2.0, Unknown licenses found

Licenses found

Apache-2.0
LICENSE
Unknown
LICENSE.zh_CN

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published