<commit_before>Jokes API example in Go lang
============================

This is a basic example of a RESTful API which serves jokes from the internet and a client to make requesting jokes easier.

This is my first ever Go program so its probably not going to be idiomatic Go lang and not a good example of a "real life" API.

The main purpose is for me to try out some of the Go concepts I have learnt about in a [Tour of Go](http://tour.golang.org/) and a starting point for a Go lang Dojo at work.

The code will only use packages from the [standard library](http://golang.org/pkg/).

TODO:
-----
* Figure out how to write tests (yes, not doing TDD as I don't even know the syntax yet!)
    * Go 'testing' package
    * Go 'net/http/httptest' package
    * Testify - https://github.com/stretchr/testify
    * Gingko - BDD
    * GoConvery - BDD

Setup
-----

Install Go compiler and tools: https://golang.org/doc/install

On Mac OS X, you can use [Homebrew](http://brew.sh/):

    brew install go

Prepare your Go workspace and set your [GOPATH](https://golang.org/doc/code.html#GOPATH):

    $ mkdir -p $HOME/go/{src,pkg,bin}
    $ export GOPATH=$HOME/go
    $ echo "export GOPATH=$HOME/go" >> ~/.bashrc

Read more about Go lang [workspaces](https://golang.org/doc/code.html#Workspaces).

Fetch this project into your Go workspace:

    $ cd $GOPATH
    $ go get github.com/clarenceb/jokes_api_golang

Using the Server
----------------

    # Build the server
    cd $GOPATH/src/github.com/clarenceb/jokes_api/server
    go build

    # Run the server (on port localhost:8080)
    ./server

    # Test server with curl:
    curl -H "Accept: application/json" http://localhost:8080/joke
    # => {"joke":"<NAME> finished World of Warcraft."}

Using the Client
----------------

    # Build the client
    cd $GOPATH/src/github.com/clarenceb/jokes_api/client
    go build

    # View usage
    ./client --help

    # Fetch one joke
    ./client
    # => 1: Chuck Norris finished World of Warcraft.

    # Fetch multiple jokes
    ./client -n 2
    # => 1: No one has ever spoken during review of Chuck Norris' code and lived to tell about it.
    # => 2: Chuck Norris once ate four 30lb bowling balls without chewing.

    # Fetch multiple jokes concurrently
    ./client -n 2
    # => 2: Chuck Norris once ate four 30lb bowling balls without chewing.
    # => 1: No one has ever spoken during review of Chuck Norris' code and lived to tell about it.

About `jokes_api/server`
-----------------------

Demonstrates:

* HTTP RESTful API
* JSON encoding / decoding of messages
* Basic logging for debugging / troubleshooting
* Error handling
* Testing

About `jokes_api/client`
-----------------------

Demonstrates:

* Command-line tool
* Parsing command-line arguments
* Making concurrent HTTP client requests (via goroutines and channels)
* Error handling
* Packages and splitting code over multiple files
* Testing

Potential Improvements
----------------------

Further Learning
----------------

* Start here: [Tour of Go](http://tour.golang.org/)<commit_msg>Updated README with TODOs<commit_after>Jokes API example in Go lang
============================

This is a basic example of a RESTful API which serves jokes from the internet and a client to make requesting jokes easier.

This is my first ever Go program so its probably not going to be idiomatic Go lang and not a good example of a "real life" API.

The main purpose is for me to try out some of the Go concepts I have learnt about in a [Tour of Go](http://tour.golang.org/) and a starting point for a Go lang Dojo at work.

The code will only use packages from the [standard library](http://golang.org/pkg/).

TODO:
-----
* Figure out how to write tests (yes, not doing TDD as I don't even know the syntax yet!)
    * Go 'testing' package
    * Go 'net/http/httptest' package
    * Testify - https://github.com/stretchr/testify
    * Gingko - BDD
    * GoConvery - BDD

Setup
-----

Install Go compiler and tools: https://golang.org/doc/install

On Mac OS X, you can use [Homebrew](http://brew.sh/):

    brew install go

Prepare your Go workspace and set your [GOPATH](https://golang.org/doc/code.html#GOPATH):

    $ mkdir -p $HOME/go/{src,pkg,bin}
    $ export GOPATH=$HOME/go
    $ echo "export GOPATH=$HOME/go" >> ~/.bashrc

Read more about Go lang [workspaces](https://golang.org/doc/code.html#Workspaces).

Fetch this project into your Go workspace:

    $ cd $GOPATH
    $ go get github.com/clarenceb/jokes_api_golang

Using the Server
----------------

    # Build the server
    cd $GOPATH/src/github.com/clarenceb/jokes_api/server
    go build

    # Run the server (on port localhost:8080)
    ./server

    # Test server with curl:
    curl -H "Accept: application/json" http://localhost:8080/joke
    # => {"joke":"<NAME> finished World of Warcraft."}

Using the Client
----------------

    # Build the client
    cd $GOPATH/src/github.com/clarenceb/jokes_api/client
    go build

    # View usage
    ./client --help

    # Fetch one joke
    ./client
    # => 1: <NAME> finished World of Warcraft.

    # Fetch multiple jokes
    ./client -n 2
    # => 1: No one has ever spoken during review of Chuck Norris' code and lived to tell about it.
    # => 2: Chuck Norris once ate four 30lb bowling balls without chewing.

    # Fetch multiple jokes concurrently
    ./client -n 2
    # => 2: Chuck Norris once ate four 30lb bowling balls without chewing.
    # => 1: No one has ever spoken during review of <NAME>' code and lived to tell about it.

About `jokes_api/server`
-----------------------

Demonstrates:

* HTTP RESTful API
* JSON encoding / decoding of messages
* Basic logging for debugging / troubleshooting
* Error handling
* TODO: Testing

About `jokes_api/client`
-----------------------

Demonstrates:

* Command-line tool
* Parsing command-line arguments
* Making concurrent HTTP client requests (via goroutines and channels)
* Error handling
* Packages and splitting code over multiple files
* TODO: Testing

Potential Improvements
----------------------

Further Learning
----------------

* Start here: [Tour of Go](http://tour.golang.org/)
{'fraction_non_alphanumeric': 0.13513513513513514, 'fraction_numerical': 0.006186909801367633, 'mean_word_length': 2.7095410628019323, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 23, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '841670', 'n_tokens_mistral': 1925, 'n_tokens_neox': 1766, 'n_words': 734}