-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
281 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
version = "3.8.2" | ||
runner.dialect = scala3 | ||
rewrite.scala3.insertEndMarkerMinLines = 5 | ||
rewrite.scala3.removeOptionalBraces = true | ||
rewrite.scala3.convertToNewSyntax = true | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# smithy4s-curl | ||
|
||
<!--toc:start--> | ||
|
||
- [smithy4s-curl](#smithy4s-curl) | ||
- [Installation](#installation) | ||
- [Getting started](#getting-started) | ||
- [Contributing](#contributing) | ||
<!--toc:end--> | ||
|
||
An _experimental_ [Smithy4s](https://disneystreaming.github.io/smithy4s/) client backend for [Scala Native](https://www.scala-native.org/), using Curl directly, without introducing a http4s/cats dependency. | ||
|
||
The purpose of the library is to provide a synchronous client implementation for smithy4s services, suitable for usage in CLIs where introducing http4s/cats dependency just to interact with a smithy4s service is undesirable. | ||
|
||
The library is currently only available for Scala 3, but we will welcome contributions cross-compiling it to 2.13 – it should be very easy. API surface is very minimal and designed for binary compatible evolution, so after initial round of testing and gathering community feedback, we plan to release 1.0.0 and start checking binary/Tasty compatibility for each release. | ||
|
||
Additionally, the library is currently published for Scala Native 0.4, but only for as long as smithy4s core stays on SN 0.4 – once it's published for SN 0.5, this library will jump straight to that. | ||
|
||
## Installation | ||
|
||
Latest version: [![smithy4s-curl Scala version support](https://index.scala-lang.org/neandertech/smithy4s-curl/smithy4s-curl/latest.svg)](https://index.scala-lang.org/neandertech/smithy4s-curl/smithy4s-curl) | ||
|
||
- **SBT**: `libraryDependencies += "tech.neander" %%% "smithy4s-curl" % "<latest version>"` | ||
- **Scala CLI**: `//> using dep tech.neander::smithy4s-curl::<latest version>` | ||
- **Mill**: `ivy"tech.neander::smithy4s-curl::<latest version>"` | ||
|
||
## Getting started | ||
|
||
For example's sake, let's say we have a smithy4s service that models one of the endpoints from https://httpbin.org, defined using [smithy4s-deriving](https://github.com/neandertech/smithy4s-deriving) (note we're using [Scala CLI](https://scala-cli.virtuslab.org) for this demo): | ||
|
||
```scala | ||
//> using dep "tech.neander::smithy4s-deriving::0.0.2" | ||
//> using platform scala-native | ||
//> using scala 3.4.2 | ||
//> using option -Wunused:all | ||
|
||
import scala.annotation.experimental | ||
import smithy4s.*, deriving.{given, *}, aliases.* | ||
|
||
case class Response(headers: Map[String, String], origin: String, url: String) | ||
derives Schema | ||
|
||
@experimental | ||
trait HttpbinService derives API: | ||
@readonly | ||
@httpGet("/get") | ||
def get(): Response | ||
``` | ||
|
||
***Note** that we only need to use `@experimental` annotation because we are using smithy4s-deriving.* | ||
*If you're creating clients for services generated by standard Smithy4s codegen, just remove all `@experimental` annotations* | ||
*you see.* | ||
|
||
To create a Curl client for this service all we need to do is this: | ||
|
||
```scala | ||
import smithy4s_curl.* | ||
|
||
@main @experimental | ||
def helloWorld = | ||
val service: HttpbinService = | ||
SimpleRestJsonCurlClient( | ||
API.service[HttpbinService], | ||
"https://httpbin.org" | ||
).make.unliftService | ||
|
||
println(service.get()) | ||
``` | ||
|
||
Note that you need to have Curl library enabled, and a `-lcurl` flag added to the Scala Native linking flags | ||
|
||
## Contributing | ||
|
||
If you see something that can be improved in this library – please contribute! | ||
|
||
This is a relatively standard Scala CLI project, even though the tests run a | ||
Scala version newer than the library itself (library is published for 3.3, tests are | ||
in 3.4, to make use of smithy4s-deriving). | ||
|
||
Here are some useful commands: | ||
|
||
- `make test` – run tests | ||
- `make check-docs` – verify that snippets in `README.md` (this file) compile | ||
- `make pre-ci` – format the code so that it passes CI check | ||
- `make run-example` – run example from README against real https://httpbin.org |
Oops, something went wrong.