Coder Social home page Coder Social logo

karamokoisrael / hexagonal-bazel Goto Github PK

View Code? Open in Web Editor NEW

This project forked from zntrio/hexagonal-bazel

0.0 0.0 0.0 453 KB

Monorepo / Golang 1.18 / Hexagonal Architecture / Bazel ..... #Bingo

License: Apache License 2.0

Go 29.66% Makefile 0.78% HTML 0.93% Starlark 68.63%

hexagonal-bazel's Introduction

Bazel / Golang / Hexagonal Architecture

A little bit over-engineered urlshortener service to demonstrate Hexagonal Architecture usage with Bazel.

Build

You need to install bazelisk

$ brew install bazelisk
or
$ nix-shell -p bazelisk

Compile the world

$ make bazel-build

Run

Start the datastore

bazelisk run //cmd/urlshortener-datastore

Start the API in a different console

bazelisk run //cmd/urlshortener-api

Start the GraphQL API in a different console

bazelisk run //cmd/urlshortener-graphql

Tests

Public links

Create a shortened URL.

$ curl -d '{"url":"https://blog.zenithar.org"}' http://localhost:3000/api/v1/links
{"link":{"id":"TwkS2HS7s","url":"https://blog.zenithar.org"}}
$ curl http://localhost:3000/api/v1/links/TwkS2HS7s
{"link":{"id":"TwkS2HS7s","url":"https://blog.zenithar.org"}}

Secret links

Create a secret shortened URL.

$ curl -d '{"url":"https://blog.zenithar.org","secret":"my-very-secret-password"}' http://localhost:3000/api/v1/links
{"link":{"id":"pjuesJ9YX","url":"https://blog.zenithar.org","secret_required":true}}

Resolve the secret shortened URL (POST)

$ curl -d '{"secret":"my-very-secret-password"}' http://localhost:3000/api/v1/links/pjuesJ9YX
{"link":{"id":"pjuesJ9YX","url":"https://blog.zenithar.org"}}

If you try to access the secret shortened url with an invalid secret (POST)

$ curl -d '{"secret":"my-secret"}' http://localhost:3000/api/v1/links/pjuesJ9YX
{"error_message":"This shortened url requires a valid secret to be revealed.","error_code":403}

If you try to access the secret shortened url without the secret (GET)

$ curl http://localhost:3000/api/v1/links/pjuesJ9YX
{"error_message":"This shortened url requires a secret to be revealed.","error_code":406}

This should return a 404 to prevent the information leak about the fact that the given shortened ID exists. But be aware that it could also be identified using time based analysis.

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.