<commit_before>
# Teapot
A light-weight URLSession wrapper for building simple API clients.

<img src="./teapot.png" width=257 height=200 />

Teapot consists of a only three simple structures: a JSON optional-like container, a NetworkResult container and the Teapot itself, that acts as a nice thin wrapper around URLSession.

### JSON
The `JSON` structure is simple enum with two cases: dictionary and array. The API is designed considering that the routing model should know if the JSON will be a dictionary or an array, but also to accommodate for cases where they won’t.

```swift
// We know this API endpoint always returns a dictionary
guard let json = json?.dictionary else { return }

// Here we can have both:
switch json {
case .dictionary(let dict):
    // Handle dictionary case
case .array(let ary):
    // handle array case
}
```

### NetworkRessult
The `NetworkRessult` is responsible for encapsulating the success/failure of our API request and providing us with the relevant objects for either case.

```swift
self.teapot.get("path") { result in
    switch result {
    case .success(let json, let response):
        // handle success case, JSON is an optional
        if response.status == 204 {
            // no content
        }
    case .failure(let json, let response, let error):
        // handle failure case. json is an optional.
    }
}
```

### Teapot itself
Our cutely named Teapot is the wrapper itself. It’s instantiated with a base URL and exposes four main methods: a `get`, a `post` , a `put` and a `delete` method. It also has a stub `patch` method if your API interface requires it.

### Example API client

```swift
class APIClient {
    var teapot: Teapot
    init(baseURL: URL) {<commit_msg>Update README.md (#3)<commit_after>
# Teapot
A light-weight URLSession wrapper for building simple API clients.

<img src="./teapot.png" width=257 height=200 />

Teapot consists of a only three simple structures: a JSON optional-like container, a NetworkResult container, and the Teapot itself, that acts as a nice thin wrapper around URLSession.

### JSON
The `JSON` structure is simple enum with two cases: dictionary and array. The API is designed considering that the routing model should know if the JSON will be a dictionary or an array, but also to accommodate for cases where they won’t.

```swift
// We know this API endpoint always returns a dictionary
guard let json = json?.dictionary else { return }

// Here we can have both:
switch json {
case .dictionary(let dict):
    // Handle dictionary case
case .array(let ary):
    // handle array case
}
```

### NetworkResult
The `NetworkResult` is responsible for encapsulating the success/failure of our API request and providing us with the relevant objects for either case.

```swift
self.teapot.get("path") { result in
    switch result {
    case .success(let json, let response):
        // handle success case, JSON is an optional
        if response.status == 204 {
            // no content
        }
    case .failure(let json, let response, let error):
        // handle failure case. json is an optional.
    }
}
```

### Teapot itself
Our cutely named Teapot is the wrapper itself. It’s instantiated with a base URL and exposes four main methods: a `get`, a `post`, a `put`, and a `delete` method. It also has a stub `patch` method if your API interface requires it.

### Example API client

```swift
class APIClient {
    var teapot: Teapot
    init(baseURL: URL) {
{'fraction_non_alphanumeric': 0.0835975785528971, 'fraction_numerical': 0.005477082732776016, 'mean_word_length': 3.4316730523627075, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1284228', 'n_tokens_mistral': 965, 'n_tokens_neox': 924, 'n_words': 474}