Comments (3)
Thank you! We will approve and add these packages with #7220.
from packagelist.
Overview
This package is meant as a very simple HTTP client for use in HTTP connections that send an/or return JSON data. Just add it to your Swift Package Dependencies and free your time to work on the API (urls, endpoints, types returned etc) layer.
Methods available:
func get<T: Decodable>(_ url: URL, headers httpHeaders: [String: String]?) async throws -> T
func postJSON<T: Decodable>(_ url: URL, body: Data, httpHeaders: [String: String]?) async throws -> T
Note that the postJSON
method automatically adds { "Content-Type": "application.json" } to the URLRequest headers.
The POST method's Data
parameter doesn't need to be JSON related, but the method expects that some serialized JSON data will be returned, which it will try to decode to the type specified on it's invocation.
Usage examples:
public struct MovieSummary: Codable {
public let id: Int
public let overview: String
public let posterPath: String
public let releaseDate: String
public let title: String
public let voteAverage: Double
}
final class MoviesAPI {
func fetchPopularMovies() async throws -> [MovieSummary] {
let popularMoviesPage: MovieSummariesPage = try await JSONHttpClient.shared.get(popularMoviesURL, headers: apiHeaders)
return popularMoviesPage.movieSummaries
}
}
*The example above uses the The Movie Database free API to fetch popular movies and related info.
Supported iOS Versions
This package is meant to work with iOS 13 onwards.
Contact
Licensing
MIT Lisense
Copyright (c) 2024 Otavio Zabaleta
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
from packagelist.
Thanks!
from packagelist.
Related Issues (20)
- Add AlertHandlerKit HOT 2
- Add PatternAuthentication
- Add PatternAuthentication HOT 1
- Add PatternAuthentication HOT 2
- Add Registry HOT 1
- Add numerix HOT 2
- Add apple-maps-kit HOT 2
- Test
- Add InfinityScrollKit HOT 2
- Add Chip8iEmulationCore HOT 2
- Add swift-async-operations HOT 1
- Add EasyToast HOT 2
- Add swift-composable-loadable HOT 3
- Add `swift-json-schema` HOT 2
- Add FaceLiveness HOT 2
- Add ExecuTorch HOT 1
- Add ExecuTorch HOT 1
- Add ExecuTorch HOT 2
- Add ValidatorKit HOT 2
- Add swift-composable-loadable HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from packagelist.