https://github.com/scommons/scommons-api
Common REST API Scala/Scala.js components
https://github.com/scommons/scommons-api
ajax-request api api-client api-interface api-rest apis http joda-time rest rest-api rest-client scala scala-js scalajs
Last synced: 3 months ago
JSON representation
Common REST API Scala/Scala.js components
- Host: GitHub
- URL: https://github.com/scommons/scommons-api
- Owner: scommons
- License: apache-2.0
- Created: 2018-04-24T06:51:28.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2024-03-09T14:25:41.000Z (about 1 year ago)
- Last Synced: 2025-01-08T04:14:31.781Z (5 months ago)
- Topics: ajax-request, api, api-client, api-interface, api-rest, apis, http, joda-time, rest, rest-api, rest-client, scala, scala-js, scalajs
- Language: Scala
- Homepage: https://scommons.github.io/scommons-api
- Size: 137 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/scommons/scommons-api/actions/workflows/ci.yml?query=workflow%3Aci+branch%3Amaster)
[](https://coveralls.io/github/scommons/scommons-api?branch=master)
[](https://index.scala-lang.org/scommons/scommons-api/scommons-api-core)
[](https://www.scala-js.org)## scommons-api
Common REST API Scala/Scala.js components### How to add it to your project
```scala
val scommonsApiVer = "1.0.0-SNAPSHOT"libraryDependencies ++= Seq(
// shared
"org.scommons.api" %%% "scommons-api-core" % scommonsApiVer,
"org.scommons.api" %%% "scommons-api-joda-time" % scommonsApiVer,// client/js only
"org.scommons.api" %%% "scommons-api-xhr" % scommonsApiVer,
// server/jvm only
"org.scommons.api" %% "scommons-api-play-ws" % scommonsApiVer
)
```Latest `SNAPSHOT` version is published to [Sonatype Repo](https://oss.sonatype.org/content/repositories/snapshots/org/scommons/), just make sure you added
the proper dependency resolver to your `build.sbt` settings:
```scala
resolvers += "Sonatype Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots/"
```### How to use it
#### Joda Date/Time
You can use in your shared API data case classes date/time types from
the [joda](https://www.joda.org/joda-time/) library:
```scala
import org.joda.time._
import play.api.libs.json._case class User(firstName: String,
lastName: String,
registeredAt: DateTime,
birthDate: LocalDate,
birthTime: LocalTime)object User {
// you only need to provide appropriate implicits:
import scommons.api.jodatime.JodaTimeImplicits.{dateTimeReads => dtReads, dateTimeWrites => dtWrites}
import scommons.api.jodatime.JodaTimeImplicits.{dateReads => dReads, dateWrites => dWrites}
import scommons.api.jodatime.JodaTimeImplicits.{timeReads => tReads, timeWrites => tWrites}implicit val jsonFormat: Format[User] = Json.format[User]
}
```For `JS` part the following types are defined as wrappers around
the corresponding `ISO time formatted string`
and do not contain any logic:
- [DateTime](joda-time/js/src/main/scala/org/joda/time/DateTime.scala) => [tests](joda-time/js/src/test/scala/org/joda/time/DateTimeSpec.scala)
- [LocalDate](joda-time/js/src/main/scala/org/joda/time/LocalDate.scala) => [tests](joda-time/js/src/test/scala/org/joda/time/LocalDateSpec.scala)
- [LocalTime](joda-time/js/src/main/scala/org/joda/time/LocalTime.scala) => [tests](joda-time/js/src/test/scala/org/joda/time/LocalTimeSpec.scala)Once you receive from an API on `JS` side an object that uses them
you can use `toString` method to get an `ISO time formatted string`
and pass it to your favorite `JS time library` to parse it.For example, you could use standard [JS Date](https://www.w3schools.com/jS/js_date_methods.asp)
class to parse it:
```scala
import scala.scalajs.jsnew js.Date(user.registeredAt.toString).getDate
```### How to Build
To build and run all the tests use the following command:
```bash
sbt test
```## Documentation
You can find more documentation [here](https://scommons.github.io/scommons-api)