Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vanities/fourchanapi
Swift Combine adapter for 4chan's public API
https://github.com/vanities/fourchanapi
4chan combine swift
Last synced: about 1 month ago
JSON representation
Swift Combine adapter for 4chan's public API
- Host: GitHub
- URL: https://github.com/vanities/fourchanapi
- Owner: vanities
- License: mit
- Created: 2022-05-28T02:19:45.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-03-28T23:59:12.000Z (9 months ago)
- Last Synced: 2024-03-29T00:34:45.138Z (9 months ago)
- Topics: 4chan, combine, swift
- Language: Swift
- Homepage:
- Size: 28.3 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# FourChan
A Swift package for the [4chan.org Read-only HTTP/JSON API](https://github.com/4chan/4chan-API).
# Features
- Typesafe URLs for
- the 4chan API (FourChanAPIEndpoint)
- the experimental 4chan mobile search API (FourChanAPIEndpoint.search)
- the 4chan web site. (FourChanWebEndpoint)
- Codable structs for all the 4chan API result types (e.g. Post).
- the structs implement Identifiable where possible.
- Helpers for making network requests in a variety of styles:
- using callbacks.
- using Combine publishers.
- using Combine/SwiftUI ObsevableObjects.# Usage
This package supports both callback and Combine-based networking.
If you load the package in an environment (like Linux) that doesn't support Combine, then the Combine APIs won't be available.
An example of using the API with minimal helper functions:
```
import Foundation
import FourChanlet boards = try? JSONDecoder().decode(Boards.self,
from:Data(contentsOf:FourChanAPIEndpoint.boards.url()))```
An example of callback-based networking is:
```
import FourChanFourChanAPIService.shared.GET(endpoint:.boards) { (result: Result) in
print(result)
}
```An example of Combine-based networking:
```
import CombineFourChanService.shared.posts(board:"w")
.tryMap{ postInContext in
postInContext.imageURL
}
.sink(
receiveCompletion: { completion in
if case .failure(_) = completion {
print(".sink() failed ", String(describing: completion))
}
},
receiveValue: { imageURL in
print(imageURL)
}
)
```A SwiftUI example:
```
import FourChan
import SwiftUIstruct FourChanBoardsView : View {
var loader: FourChanLoader = FourChanLoader()var body: some View {
var categories = loader.data?.categories ?? []
return List {
ForEach(0..