Giter Site home page Giter Site logo

afleishaker / smithy4s-api-demonstration Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 7 KB

An example of leveraging smithy4s for use in API development with http4s and a CLI using decline, yielding a functional, cats-effect-backed Scala service. :hammer::arrow_right::link:

Scala 88.16% HCL 3.20% Smithy 8.64%
api cats-effect http4s scala smithy smithy4s cli

smithy4s-api-demonstration's Introduction

๐Ÿ”จโžก๏ธ๐Ÿ”— smithy4s-api-demonstration

An example of leveraging smithy4s to describe and generate traits to use in API development with http4s and a CLI using decline. Using Localstack to interface to local DynamoDB, this demo yields a functional, cats-effect-backed Scala service.

Smithy

smithy4s implements Scala codegen off of specifications of Smithy, an IDL by AWS.

In this demo, we define a JobsService to retrieve and persist job listings. Given the operations and structures in our spec, smithy4s provides Scala traits defining route methods for us to implement and wire into http4s.

Architecture

To power the API we implement based on our spec above, this demo defines a singular DynamoDB table in Terraform to store our job listings.

Usage

Pre-steps

  1. Install Terraform to execute the Terraform containing our DDB table
  2. Install terraform-local with pip to get a Terraform wrapper macro, tflocal, which points your Terraform commands to our Localstack
  3. Install awscli-local with pip to get an AWS CLI wrapper macro, awslocal, which points your AWS CLI commands to our Localstack

Stand-up

  1. Stand up the containers with: docker-compose up
  2. Apply your Terraform infrastructure to the Localstack container with:
tflocal init
tflocal apply --auto-approve
  1. Start the API with: sbt run

Interacting with the API

Once stood up, the API is live at https://localhost:9000.

  • smithy4s generates Swagger docs at https://localhost:9000/docs, which can be used to test GET or POST on the implemented routes
  • This can also be accomplished with the smithy4s-generated CLI, accessible at: sbt jobs-service
  • Finally, the docker-compose also contains dynamodb-admin for local DDB viewing, accessible at: http://localhost:8001/

smithy4s-api-demonstration's People

Contributors

afleishaker avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.