Skip to content

charlotth/fizzbuzz

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fizzbuzz

Exercise: Write a simple fizz-buzz REST server. "The original fizz-buzz consists in writing all numbers from 1 to 100, and just replacing all multiples of 3 by ""fizz"", all multiples of 5 by ""buzz"", and all multiples of 15 by ""fizzbuzz"". The output would look like this: ""1,2,fizz,4,buzz,fizz,7,8,fizz,buzz,11,fizz,13,14,fizzbuzz,16,...""." Your goal is to implement a web server that will expose a REST API endpoint that:

  • Accepts five parameters: three integers int1, int2 and limit, and two strings str1 and str2.
  • Returns a list of strings with numbers from 1 to limit, where: all multiples of int1 are replaced by str1, all multiples of int2 are replaced by str2, all multiples of int1 and int2 are replaced by str1str2. The server needs to be:
  • Ready for production
  • Easy to maintain by other developers Bonus: add a statistics endpoint allowing users to know what the most frequent request has been. This endpoint should:
  • Accept no parameter
  • Return the parameters corresponding to the most used request, as well as the number of hits for this request
go get github.com/tcharlot-datasweet/fizzbuzz
go run cmd\server.go

# Call /fizzbuzz API
curl -XPOST localhost:8081/fizzbuzz -H "Content-type:application/json"
curl -XPOST localhost:8081/fizzbuzz -H "Content-type:application/json" -d '{"limit": 10}'
curl -XPOST localhost:8081/fizzbuzz -H "Content-type:application/json" -d '{"limit": 152, "int1": 7, "str1": "FIZZZZ", "int2": 8, "str2": "BUZZZZZ"}'

# NEW with GET 
curl localhost:8081/fizzbuzz
curl localhost:8081/fizzbuzz?limit=10
curl localhost:8081/fizzbuzz?limit=152&int1=7&str1=FIZZZZ&int2=8&str2=BUZZZZZ

# Call /stats API
curl localhost:8081/stats/all
curl localhost:8081/stats/mostused

Testing

go test -v ./...

About

Fizzbuzz rest server

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages