Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/neandertech/smithy4s-curl
Curl-based Scala Native client implementation for Smithy4s services
https://github.com/neandertech/smithy4s-curl
curl scala scala3 scalanative smithy4s
Last synced: 23 days ago
JSON representation
Curl-based Scala Native client implementation for Smithy4s services
- Host: GitHub
- URL: https://github.com/neandertech/smithy4s-curl
- Owner: neandertech
- Created: 2024-07-01T20:43:30.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2024-07-19T10:00:17.000Z (4 months ago)
- Last Synced: 2024-10-01T02:40:15.707Z (about 1 month ago)
- Topics: curl, scala, scala3, scalanative, smithy4s
- Language: Scala
- Homepage:
- Size: 97.7 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# smithy4s-curl
- [smithy4s-curl](#smithy4s-curl)
- [Installation](#installation)
- [Getting started](#getting-started)
- [Contributing](#contributing)
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" % ""`
- **Scala CLI**: `//> using dep tech.neander::smithy4s-curl::`
- **Mill**: `ivy"tech.neander::smithy4s-curl::"`## 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.3"
//> using platform scala-native
//> using scala 3.4.2
//> using option -Wunused:allimport scala.annotation.experimental
import smithy4s.*, deriving.{given, *}, aliases.*
import scala.util.Trycase class Response(headers: Map[String, String], origin: String, url: String)
derives Schema@experimental
trait HttpbinService derives API:
@readonly
@httpGet("/get")
def get(): Try[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 =
SimpleRestJsonCurlClient(
API.service[HttpbinService],
"https://httpbin.org",
SyncCurlClient()
).make.unliftServiceprintln(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