{"id":21862258,"url":"https://github.com/innfactory/smithy4play","last_synced_at":"2025-04-14T19:41:23.546Z","repository":{"id":48187408,"uuid":"490203001","full_name":"innFactory/smithy4play","owner":"innFactory","description":"smithy4s Routing for Play Framework.","archived":false,"fork":false,"pushed_at":"2024-11-28T00:25:51.000Z","size":790,"stargazers_count":14,"open_issues_count":19,"forks_count":1,"subscribers_count":7,"default_branch":"main","last_synced_at":"2024-11-28T01:26:04.107Z","etag":null,"topics":["play2","play3","scala","scala3","smithy","smithy4s"],"latest_commit_sha":null,"homepage":"https://innfactory.de","language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/innFactory.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-05-09T08:47:06.000Z","updated_at":"2024-11-28T00:25:20.000Z","dependencies_parsed_at":"2023-09-26T05:06:26.202Z","dependency_job_id":"416bd3ed-c8fd-4f45-b0d4-45ea1f295366","html_url":"https://github.com/innFactory/smithy4play","commit_stats":null,"previous_names":[],"tags_count":39,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/innFactory%2Fsmithy4play","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/innFactory%2Fsmithy4play/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/innFactory%2Fsmithy4play/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/innFactory%2Fsmithy4play/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/innFactory","download_url":"https://codeload.github.com/innFactory/smithy4play/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226851508,"owners_count":17692126,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["play2","play3","scala","scala3","smithy","smithy4s"],"created_at":"2024-11-28T03:14:30.292Z","updated_at":"2024-11-28T03:14:31.005Z","avatar_url":"https://github.com/innFactory.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"![](docs/smithy4play.png)\n![GitHub last commit](https://img.shields.io/github/last-commit/innFactory/smithy4play)\n[![Scala Build and Test CI](https://github.com/innFactory/smithy4play/actions/workflows/build.yml/badge.svg)](https://github.com/innFactory/smithy4play/actions/workflows/build.yml)\n\n# Smithy4Play\n\nsmithy4play is a routing gernator for the play2 framework based on [smithy4s](https://github.com/disneystreaming/smithy4s). Just write your smithy API definition and the plugin will generate everything you need for play2 framework usage.\n\n---\n\n## QuickStart \n### Add smithy4play to your project \n\nplugins.sbt\n\n```scala\naddSbtPlugin(\"com.typesafe.play\" % \"sbt-plugin\" % \"2.*.*\")\naddSbtPlugin(\"com.codecommit\" % \"sbt-github-packages\" % \"0.*.*\")\naddSbtPlugin(\n  \"com.disneystreaming.smithy4s\" % \"smithy4s-sbt-codegen\" % \"0.*.*\"\n)\n```\n\nbuild.sbt\n\n```scala\n.enablePlugins(Smithy4sCodegenPlugin, PlayScala)\n  .settings(\n    githubSettings,\n    Compile / smithy4sInputDir := (ThisBuild / baseDirectory).value / \"smithy-in\",\n    Compile / smithy4sOutputDir := (ThisBuild / baseDirectory).value / \"smithy-out\",\n    libraryDependencies += \"de.innfactory\" %% \"smithy4play\" % \"latestVersion\")\n```\n\n### Usage\n\n- define your controllers in smithy files\n- use smithy4s codegen (sbt compile)\n\n**Server**\n- create controller scala class\n- extend your Controller with the generated Scala Type and smithy4play Type ContextRoute\n\n```scala\n@Singleton\nclass PreviewController @Inject(\n)(implicit\n  cc: ControllerComponents,\n  ec: ExecutionContext\n ) extends PreviewControllerService[ContextRoute] {\n\n  override def preview(bye: PreviewBody): ContextRoute[PreviewResponse] =\n    Kleisli { rc =\u003e\n      EitherT.rightT[Future, ContextRouteError](PreviewResponse(Some(\"Hello\")))\n    }\n}\n```\n\n**Client**\n- import the EnhancedGenericAPIClient\n```scala\nimport de.innfactory.smithy4play.client.GenericAPIClient.EnhancedGenericAPIClient\nval previewControllerClient = PreviewControllerServiceGen.withClient(FakeRequestClient)\npreviewControllerClient.preview()\n```\nFor a further examples take a look at the smithy4playTest project.\n\n## Routing\n\nYou can choose between autorouting or selfbinding.\n\n### Autorouting\n\n- Annotate your controller with ```@AutoRouting```\n- add ```scalacOptions += \"-Ymacro-annotations\"``` to your build.sbt settings to enable macro annotations\n- bind the smithy4play AutoRouter in the play routes file\n\n```scala\n-\u003e / de.innfactory.smithy4play.AutoRouter\n```\n- add package name to configuration\n```scala\nsmithy4play.autoRoutePackage = \"your.package.name\"\n```\n\n### Selfbinding\n\n- Create a ApiRouter class and inject your controller\n\n```scala\n@Singleton\nclass ApiRouter @Inject()(\n  homeController: HomeController,\n  pizzaController: PizzaController\n)(implicit\n  cc: ControllerComponents,\n  ec: ExecutionContext\n) extends BaseRouter {\n\n  override val controllers: Seq[Routes] =\n    Seq(homeController, pizzaController)\n}\n\n```\n\n- bind the ApiRouter in the play routes file\n\n```scala\n-\u003e / api.ApiRouter\n```\n\n## Middlewares\n\nIf you want Middlewares that run before the endpoint logic follow these steps:\n\n- Implement Middlewares\n```scala\n@Singleton\nclass ExampleMiddleware @Inject() (implicit\n  executionContext: ExecutionContext\n) extends MiddlewareBase {\n\n  override protected def skipMiddleware(r: RoutingContext): Boolean = false\n\n  override def logic(\n    r: RoutingContext,\n    next: RoutingContext =\u003e RouteResult[EndpointResult]\n  ): RouteResult[EndpointResult] =\n    next(r)\n}\n```\n- Implement a MiddlewareRegistry and register your middlewares\n```scala\nclass MiddlewareRegistry @Inject() (\n  disableAbleMiddleware: DisableAbleMiddleware,\n  testMiddlewareImpl: TestMiddlewareImpl,\n  validateAuthMiddleware: ValidateAuthMiddleware\n) extends MiddlewareRegistryBase {\n  override val middlewares: Seq[MiddlewareBase] = Seq(ExampleMiddleware)\n}\n```\n\n\n## Credits:\n\n[innFactory ❤️ Open Source](https://innfactory.de)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finnfactory%2Fsmithy4play","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finnfactory%2Fsmithy4play","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finnfactory%2Fsmithy4play/lists"}