Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zonble/curldsl
CurlDSL converts cURL commands into URLRequest objects
https://github.com/zonble/curldsl
curl dsl ios networking swift
Last synced: 10 days ago
JSON representation
CurlDSL converts cURL commands into URLRequest objects
- Host: GitHub
- URL: https://github.com/zonble/curldsl
- Owner: zonble
- License: mit
- Created: 2019-08-03T12:45:43.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-11-19T14:39:21.000Z (about 3 years ago)
- Last Synced: 2024-11-14T16:47:02.370Z (about 1 month ago)
- Topics: curl, dsl, ios, networking, swift
- Language: Swift
- Homepage: https://zonble.github.io/CurlDSL
- Size: 160 KB
- Stars: 69
- Watchers: 3
- Forks: 8
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# CurlDSL
2019 © Weizhong Yang a.k.a zonble
[![Actions Status](https://github.com/zonble/CurlDSL/workflows/Build/badge.svg)](https://github.com/zonble/CurlDSL/actions)
CurlDSL converts cURL commands into `URLRequest` objects. The Swift package
helps you to build HTTP clients in your iOS/macOS/tvOS easier, once you have a
cURL command example for a Web API endpoint.CurlDSL does not embed cURL library into your project. It is also not a Swift
code generator, but it is a simple interpreter, it parses and interprets your
cURL command at run time.The project is inspired by [cURL as DSL](https://github.com/shibukawa/curl_as_dsl)
by [Yoshiki Shibukawa](https://github.com/shibukawa).CurlDSL supports only HTTP and HTTPS right now.
## Requirement
- Swift 5.1 or above
- iOS 13 or above
- macOS 10.15 or above
- tvOS 13 or above## Installation
You can install the package via [Swift Package Manager](https://swift.org/package-manager/).
## Usage
There is only one important object, `CURL`. You can just pass your cURL command
to it. For example:``` swift
try CURL("curl -X GET https://httpbin.org/json")
```You can use it to build `URLRequest` objects.
``` swift
let request = try? CURL("curl -X GET https://httpbin.org/json").buildRequest()
```Or jsut run the data task:
``` swift
try CURL("https://httpbin.org/json").run { data, response, error in
/// Do what you like...
}
```## Supported Options
We do not support all of options of cURL. The supported options are as the
following list.``` text
-d, --data=DATA HTTP POST data (H)
-F, --form=KEY=VALUE Specify HTTP multipart POST data (H)
--form-string=KEY=VALUE Specify HTTP multipart POST data (H)
-H, --header=LINE Pass custom header LINE to server (H)
-e, --referer= Referer URL (H)
-X, --request=COMMAND Specify request command to use
--url=URL URL to work with
-u, --user=USER[:PASSWORD] Server user and password
-A, --user-agent=STRING User-Agent to send to server (H)
```## Built-in Response Handlers
The package has several built-in handlers:
- `JsonDictionaryHandler`: Decodes fetched JSON data into a dictionary.
- `CodableHandler`: Decodes fetched JSON data into Codable objects.
- `DataHandler`: Simply returns raw data.## License
The package is released under MIT license.
Pull requests are welcome.
Enjoy!