Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/algolia/algoliasearch-client-scala

⚡️ A fully-featured and blazing-fast Scala API client to interact with Algolia.
https://github.com/algolia/algoliasearch-client-scala

algolia algolia-api algolia-search api-client scala

Last synced: 2 days ago
JSON representation

⚡️ A fully-featured and blazing-fast Scala API client to interact with Algolia.

Awesome Lists containing this project

README

        



Algolia for Scala

The perfect starting point to integrate Algolia within your Scala project


Maven Central
Licence


Documentation
Community Forum
Stack Overflow
Report a bug
FAQ
Support

## ✨ Features

* Supports Scala 2.13 and 3.3
* Asynchronous methods to target Algolia's API
* Json as case class

## 💡 Getting Started

**WARNING:**
The JVM has an infinite cache on successful DNS resolution.
As our hostnames points to multiple IPs, the load could be not evenly spread among our machines,
and you might also target a dead machine.

You should change this TTL by setting the property `networkaddress.cache.ttl`.
For example, to set the cache to 60 seconds:

```scala
java.security.Security.setProperty("networkaddress.cache.ttl", "60");
```

For debug purposes, you can enable debug logging on the API client.
It's using [slf4j](https://www.slf4j.org) so it should be compatible with most java loggers.

## 💡 Getting Started

To get started, add the algoliasearch-client-scala dependency to your project, with [Maven](https://maven.apache.org/), add the following dependency to your `pom.xml` file:

```xml

com.algolia
algoliasearch-scala_2.13
[2,)

```

For snapshots, add the `sonatype` repository:
```xml


oss-sonatype
oss-sonatype
https://oss.sonatype.org/content/repositories/snapshots/

true

```

If you're using `sbt`, add the following dependency to your `build.sbt` file:

```scala
libraryDependencies += "com.algolia" %% "algoliasearch-scala" % "[2,)"
```

For snapshots, add the `sonatype` repository:
```scala
resolvers += "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots"
```

You can now import the Algolia API client in your project and play with it.

```scala
import algoliasearch.api.SearchClient

val client = SearchClient(appId = "YOUR_APP_ID", apiKey = "YOUR_API_KEY")

// Add a new record to your Algolia index
val response = client.saveObject(
indexName = "",
body = JObject(List(JField("objectID", JString("id")), JField("test", JString("val"))))
)

// Use the response
val value = Await.result(response, Duration(100, "sec"))

// Poll the task status to know when it has been indexed
client.waitTask("", response.getTaskID())

// Fetch search results, with typo tolerance
val response = client.search(
searchMethodParams = SearchMethodParams(
requests = Seq(
SearchForHits(
indexName = "",
query = Some(""),
hitsPerPage = Some(50)
)
)
)
)

// Use the response
val value = Await.result(response, Duration(100, "sec"))
```

For full documentation, visit the **[Algolia Scala API Client](https://www.algolia.com/doc/libraries/scala/)**.

## ❓ Troubleshooting

Encountering an issue? Before reaching out to support, we recommend heading to our [FAQ](https://www.algolia.com/doc/api-client/troubleshooting/faq/scala/) where you will find answers for the most common issues and gotchas with the client. You can also open [a GitHub issue](https://github.com/algolia/api-clients-automation/issues/new?assignees=&labels=&projects=&template=Bug_report.md)

## Contributing

This repository hosts the code of the generated Algolia API client for Scala, if you'd like to contribute, head over to the [main repository](https://github.com/algolia/api-clients-automation). You can also find contributing guides on [our documentation website](https://api-clients-automation.netlify.app/docs/introduction).

## 📄 License

The Algolia Scala API Client is an open-sourced software licensed under the [MIT license](LICENSE).