Fibonacci RESTful API - HTTP server that listens on a given port

Fibonacci RESTful API

Overview

HTTP server that listens on a given port following Hexagonal architecture (ports & adapters) It supports multiple connections simultaneously, and provides the following endpoints:

  • /fib/algorithm

    • input: form field named 'input' using POST to provide the value n of which the nth fibonacci number will be calculated. Input must be between 1 and 99999. POST
    • input: algorithm with which to calculate the fin number. Options: math, recursive, iterate
    • output: An incrementing identifier returns immediately.
    • example_input: curl --data "input=50" http://localhost:8000/fib/math
    • example_outut: 1
  • /find/id

    • input: id which was passed to the user from the /fib/algorithm endpoint. GET
    • output: json encoded list of details about the request. If the number is not done calculating "status" will be set to incomplete. Duration is in microseconds.
    • example_input: curl http://localhost:8000/find/1
    • example_output: {"Input":50,"Fib":7778742049,"Duration":123,"Algo":"math","Status":"complete","Id":1}
  • /shutdown

    • input: None.
    • output: Server will gracefully shutdown after waiting for all active requests to complete.

Installation

Setup

After installing GO, Clone this repo and launch server in a terminal with go run main.go port#

  • ex: go run main.go 8000. The server automatically starts on localhost

In a new terminal send your POST and GET requests.

Architecture

Code architecture follows hexagonal architecture principles, also known as ports and adapters.

This architecture is divided in three main layers:

  • Application: The outer layer. Handlers and all I/O related stuff (web framework, DB, ...). Anything that can change by an "external" cause (not by your decision), is in this layer.

  • Service: Use cases. Actions triggered by API calls, represented by application services. It includes repositories specific interfaces, known as adapters.

  • Domain: Inner layer. Business logic and rules goes here. Repositories Interfaces, known as ports, belongs to this layer.

I have also included an data transfer object (dto) abstraction layer. This allows us to control exactly what is passed back to the client.

Testing

Tests have been built with golangs built in testing package. In root directory of repo run go test ./...

Considerations made

  • I considered several approaches to the routing including gorilla mux and some regex strategies, but in the end I thought a "no router" approach was the most maintainable.
  • I did not hook a database up to this server as I didn't want to over engineer the prompt, but due the hexagonal architecture it would be pretty trivial to add one.
  • I took liberties with the prompt, making the server more RESTful.
  • I only included tests for the business logic (domain) in this example server but I would usually have tests for app, domain, and service sides.
  • If I was to iterate on this I would add more debug logging functionality, and more error checking.
Similar Resources

Basic repository with HTTP ping api and db setup

Simple API Simple REST API with database (postgres) integration HighLevel Agenda Integrating with postgres (few concepts) Live code walkthrough Detail

Jan 27, 2022

go http api to handle phishing resources requests

go http api to handle phishing resources requests (auth check, prometheus metrics, pushing to rabbit, logging to elasticsearch)

Oct 8, 2021

Weather api - A Simple Weather API Example With Golang

Example import: import "github.com/mr-joshcrane/weather_api" Example of Library

Jan 5, 2022

Prototype to show how to transform an existing (SOAP) API into a modern streaming API

vSphere Event Streaming Prototype to show how to transform an existing (SOAP) API into a modern HTTP/REST streaming API. Details The vSphere Event Str

Nov 14, 2022

Full-featured, plugin-driven, extensible HTTP client toolkit for Go

gentleman Full-featured, plugin-driven, middleware-oriented toolkit to easily create rich, versatile and composable HTTP clients in Go. gentleman embr

Dec 23, 2022

An enhanced http client for Golang

An enhanced http client for Golang

go-http-client An enhanced http client for Golang Documentation on go.dev 🔗 This package provides you a http client package for your http requests. Y

Dec 23, 2022

An enhanced HTTP client for Go

An enhanced HTTP client for Go

Heimdall Description Installation Usage Making a simple GET request Creating a hystrix-like circuit breaker Creating a hystrix-like circuit breaker wi

Jan 9, 2023

Enriches the standard go http client with retry functionality.

httpRetry Enriches the standard go http client with retry functionality using a wrapper around the Roundtripper interface. The advantage of this libra

Dec 10, 2022
Restgo - Restful http client pkg in Go

Restgo - Restful http client pkg in Go

Dec 1, 2022
Http client call for golang http api calls

httpclient-call-go This library is used to make http calls to different API services Install Package go get

Oct 7, 2022
Fast HTTP package for Go. Tuned for high performance. Zero memory allocations in hot paths. Up to 10x faster than net/http
Fast HTTP package for Go. Tuned for high performance. Zero memory allocations in hot paths. Up to 10x faster than net/http

fasthttp Fast HTTP implementation for Go. Currently fasthttp is successfully used by VertaMedia in a production serving up to 200K rps from more than

Jan 2, 2023
Speak HTTP like a local. (the simple, intuitive HTTP console, golang version)

http-gonsole This is the Go port of the http-console. Speak HTTP like a local Talking to an HTTP server with curl can be fun, but most of the time it'

Jul 14, 2021
fhttp is a fork of net/http that provides an array of features pertaining to the fingerprint of the golang http client.

fhttp The f stands for flex. fhttp is a fork of net/http that provides an array of features pertaining to the fingerprint of the golang http client. T

Jan 1, 2023
NATS HTTP Round Tripper - This is a Golang http.RoundTripper that uses NATS as a transport.

This is a Golang http.RoundTripper that uses NATS as a transport. Included is a http.RoundTripper for clients, a server that uses normal HTTP Handlers and any existing http handler mux and a Caddy Server transport.

Dec 6, 2022
Simple HTTP package that wraps net/http

Simple HTTP package that wraps net/http

Jan 17, 2022
Http-conection - A simple example of how to establish a HTTP connection using Golang

A simple example of how to establish a HTTP connection using Golang

Feb 1, 2022
A Go HTTP client library for creating and sending API requests
A Go HTTP client library for creating and sending API requests

Sling Sling is a Go HTTP client library for creating and sending API requests. Slings store HTTP Request properties to simplify sending requests and d

Jan 7, 2023
Gotcha is an high level HTTP client with a got-like API
Gotcha is an high level HTTP client with a got-like API

Gotcha is an alternative to Go's http client, with an API inspired by got. It can interface with other HTTP packages through an adapter.

Dec 7, 2022