kakapo



Installation

  1. First, open your Terminal.
  2. Next, navigate to your project directory.
  3. Then, run the following command: pod init
  4. Open the newly created Podfile and add the following line: pod 'Kakapo'
  5. Save and close the Podfile.
  6. Finally, run the command: pod install

Usage


Creating a new instance



import Kakapo
let server = Server()

Defining routes



server.route("GET", "/api/books") { _ in
// Provide route handler implementation here.
}

Handling requests



server.route("POST", "/api/books") { request in
// Handle POST request here.
// Use the provided request parameter as needed.
}

Response mocking



server.route("GET", "/api/books") { _ in
// Provide route handler implementation here.
let json = """
[
{
"id": 1,
"title": "Book 1",
"author": "Author 1"
},
{
"id": 2,
"title": "Book 2",
"author": "Author 2"
}
]
"""
return Response(status: 200, headers: ["Content-Type": "application/json"], body: json.data(using: .utf8))
}


Additional Resources