Testing the server

The easiest way to check that all is as it should be is to enter the following URL into any browser (Safari, Chrome, it doesn't matter which): http://127.0.0.1:8000/test.json.

Or, you can use this URL, which does exactly the same thing: localhost:8000/test.json.

In the browser window, you'll see the JSON data you put into test.json, pretty much as it appeared previously.

However, we are coders, are we not? Let's test the server in code, which will allow us to dig a little deeper into what is going on, and catch a first glimpse at Swift 3's new URLSession API:

  1. Create a new Cocoa Application Xcode project.
  2. Add a new Swift file, and call it HTTPRequestManager.swift.
  3. Under the import statement, add the following code:
 class ...

Get Mastering macOS Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.