Installation
- First, open your Terminal.
- Next, navigate to your project directory.
- Then, run the following command:
pod init
- Open the newly created Podfile and add the following line:
pod 'Kakapo'
- Save and close the Podfile.
- 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))
}