/PerfectArcade

An example Arcade game backend using Perfect

Primary LanguageSwiftApache License 2.0Apache-2.0

Arcade API Example

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

Arcade API backend example

Using Perfect, this example demonstrates JSON API interactions with GET and POST methods, storing and retrieving data via the SQLite3 version of StORM (a Swift ORM). HTTP Requests are logged using Perfect-RequestLogger by David Fleming.

###Compatibility with Swift

This project works only with the Swift 3.0 toolchain available with Xcode 8.0+ or on Linux via Swift.org.

Swift version note:

Due to a late-breaking bug in Xcode 8, if you wish to run directly within Xcode, we recommend installing swiftenv and installing the Swift 3.0.1 preview toolchain.

# after installing swiftenv from https://swiftenv.fuller.li/en/latest/
swiftenv install https://swift.org/builds/swift-3.0.1-preview-1/xcode/swift-3.0.1-PREVIEW-1/swift-3.0.1-PREVIEW-1-osx.pkg

Alternatively, add to the "Library Search Paths" in "Project Settings" $(PROJECT_DIR), recursive.

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/PerfectArcade.git
cd PerfectArcade
swift build
.build/debug/PerfectArcade

If you see a build error concerning OpenSSL, please see the swift version or Library Search Paths recommendations above.

You should see the following output:

Starting HTTP server on 0.0.0.0:8181 with document root ./webroot

This means the server is running and waiting for connections.

Building the Xcode Project

To build the Xcode project, run the following in Terminal with the working directory being PerfectArcade as above.

swift package generate-xcodeproj

The output:

generated: ./PerfectArcade.xcodeproj

Available Routes

POST http://localhost:8181/api/v1/save
Params: 
	user, ideally 3 letters, i.e. AAA
	score, an integer.

The save method returns a status of the action.

GET http://localhost:8181/api/v1/highscores

The highscores method returns the top 10 high scores, and the associated user.

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.