Expert in the Simplicity Swift HTTP library - a type-safe HTTP client with middleware support. Assists with building, testing, and understanding the architecture of this Swift networking library.
Expert assistant for working with the Simplicity Swift HTTP library - a type-safe HTTP client inspired by swift-openapi-generator's client design.
This skill provides deep knowledge of the Simplicity Swift HTTP library architecture, helping you:
When exploring the codebase:
- Executes requests through a middleware chain using `URLSession`
- The `send(request:)` method builds middleware chain in **reverse order**
- Middlewares execute in the order they were added (not reversed)
- Defines type-safe requests with associated `RequestBody` and `ResponseBody` types
- Provides default JSON encoding/decoding implementations
- Use `Never?` for `RequestBody` on bodyless requests (GET/DELETE)
- Intercepts requests/responses via `intercept` method
- Receives a `next` closure to continue the chain
- Can modify requests before calling `next`
- Can inspect/modify responses after `next` returns
Use these commands:
```bash
swift build
swift test
swift test --filter MiddlewareTests
swift test --filter "MiddlewareTests/middlewareCallOrder"
```
**IMPORTANT**: When running tests, run them for **all supported platforms**, not just one.
Follow these patterns for request body handling:
- Set `RequestBody` to `Never?`
- Set `httpBody` property to `nil`
- The protocol's private extensions skip body encoding automatically
- Define a concrete `Encodable` type for `RequestBody`
- Default JSON encoding is provided
- Override `encodeBody()` for custom encoding
Use Swift Testing framework patterns:
For network tests:
Key insight: The middleware chain is built in reverse, but execution is forward:
```swift
// Added in this order:
client.addMiddleware(LoggingMiddleware()) // 1
client.addMiddleware(AuthMiddleware()) // 2
// Chain built: Auth -> Logging -> URLSession
// Execution: Logging executes first, Auth second
```
Key files to reference:
When working with this codebase:
1. **Type safety first**: Leverage associated types for compile-time guarantees
2. **Middleware for cross-cutting concerns**: Auth, logging, retry logic
3. **Test with mocks**: Use `MockURLProtocol` for deterministic tests
4. **Run multi-platform tests**: Always test on all supported platforms
5. **Follow the protocol patterns**: Use `Never?` correctly for bodyless requests
**Building and testing:**
```
"Build the package and run all tests"
"Run the middleware tests only"
"Test on all platforms"
```
**Code exploration:**
```
"Show me how middleware chains work"
"Explain the HTTPRequest body handling"
"Where is JSON encoding implemented?"
```
**Implementation:**
```
"Add a new retry middleware"
"Create a request with no body"
"Mock a network response for testing"
```
Leave a review
No reviews yet. Be the first to review this skill!
# Download SKILL.md from killerskills.ai/api/skills/simplicity-swift-http-client-expert/raw