Git Product home page Git Product logo

realworld-aws-api's Introduction

realworld-aws-api

This project illustrates how to build an API in Amazon Web Services (AWS) using Go.

Goals

The main goal of this project is to illustrate how to build a maintainable real world REST API hosted in AWS using Go. To enable this I have added examples of:

CLI

The CLI provides a simple interface to access data via the API.

$ customer-cli --help
Usage: customer-cli --url=STRING <command>

Flags:
  -h, --help          Show context-sensitive help.
      --version
      --debug
      --url=STRING

Commands:
  create-customer --url=STRING --name=STRING --labels=LABELS,...
    New Customer.

  get-customer --url=STRING --id=STRING
    Read Customer.

  list-customers --url=STRING
    Read a list of Customers.

Run "customer-cli <command> --help" for more information on a command.

Reading a list of customers from the API.

$ customer-cli --url=https://xxxxxxxxxx.execute-api.us-west-2.amazonaws.com/Prod list-customers  | jq .
6:33PM INF cmd/customer-cli/commands/list_customers.go:18 > get a list of customers from the api
6:33PM INF cmd/customer-cli/apigw/apigw.go:25 > signing request host=xxxxxxxxxx.execute-api.us-west-2.amazonaws.com
{
  "customers": [
    {
      "created_at": "2020-10-22T17:38:34.242777542Z",
      "description": "test",
      "id": "01EN8P84M2P9RQJ1XV3XQR4DZM",
      "labels": [
        "test"
      ],
      "name": "test",
      "updated_at": "2020-10-22T17:38:34.242778239Z"
    },
    {
      "created_at": "2020-10-22T17:41:23.701550324Z",
      "description": "test",
      "id": "01EN8PDA3N91HNQEVV16HX6J27",
      "labels": [
        "test"
      ],
      "name": "test2",
      "updated_at": "2020-10-22T17:41:23.701551096Z"
    },
    {
      "created_at": "2020-10-23T02:21:37.259975291Z",
      "description": "test",
      "id": "01EN9M5W3BDKGR3RGCEGNSBYHQ",
      "labels": [
        "test"
      ],
      "name": "test3",
      "updated_at": "2020-10-23T02:21:37.259975968Z"
    }
  ]
}

Conventions

In this example I use a few conventions when deploying the software, this is done to support multiple environments, and branch based deploys which are common when building and testing.

  • AppName - Label given service(s) with some collective role in a system.
  • Stage - The stage where the application is running in, e.g., dev, prod.
  • Branch - The branch this release is deployed from, typically something other than main or master is only used when testing in parallel.

Deployment

Create an .envrc using the .envrc.example and update it with your settings, this is used with direnv.

cp .envrc.example .envrc

Run make to deploy the stack.

make

Client

To invoke a simple API which is authenticated using sigv4 I have included a generated client, to use this you will need AWS_REGION and AWS_PROFILE exported as environment variables.

go run cmd/customer-cli/main.go --url=https://xxxxxxxxxx.execute-api.us-west-2.amazonaws.com/Prod list-customers

Libraries

Development

To enable fast iteration on changes I have included a local development server version of the API, this runs in docker-compose and uses a bit of mock data, along with DynamoDB Local and file change watching to provide a realtime development experience.

To use this feature run.

make docker-compose

Then load up the openapi in postman, or hit the service curl as follows.

curl -v http://localhost:3000/customers | jq .

Or using the CLI with --disable-signing to avoid including sigv4 signatures.

go run cmd/customer-cli/main.go --url http://localhost:3000 --disable-signing list-customers | jq .

License

This application is released under Apache 2.0 license and is copyright Mark Wolfe.

realworld-aws-api's People

Contributors

dependabot[bot] avatar wolfeidau avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

yhorbachov

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.