API that categorizes and stores numbers based on their divisibility
Go is an open source programming language that makes it easy to build simple, reliable, and efficient software.
Gopher image by [Renee French][rf], licensed under [Creative Commons 4.0 Attributions license][cc4-by].
Tip
Implement an API that categorizes and stores numbers based on their divisibility by 3 and 5, mimicking the logic described below:
- Numbers divisible by 3: Categorized as "Type 1"
- Numbers divisible by 5: Categorized as "Type 2"
- Numbers divisible by both 3 and 5: Categorized as "Type 3"
- Other numbers: Stored as their original value
Caution
Utilize only one if statement within the core logic. Avoid else, else if, ternary operators, or switch statements.
Note
The API shall store numbers and their classifications in memory or any other support you consider appropriate.
- Numbers divisible by 3: Categorized as "Type 1"
- Numbers divisible by 5: Categorized as "Type 2"
- Numbers divisible by both 3 and 5: Categorized as "Type 3"
- Other numbers: Stored as their original value
POST
localhost:8080/numbers/
The API provides a mechanism to save a number into its collection.
name type data type description number required object (JSON) {"number":25}
http code content-type response 201
application/json
Created successfully
400
application/json
"message": "There was an error processing the request!"
GET
localhost:8080/numbers/{number}
The API allows the retrieval of a specific number's classification. If
the number is not found, the API returns 404
name type data type description number required object (JSON) /25
http code content-type response 201
application/json
{"Number": 25,"Category": "Type 2"}
404
application/json
"message": "number not found"
400
application/json
"message": "Can't convert this to an int!"
GET
localhost:8080/numbers
The API enables the retrieval of all stored numbers and their classifications.
name type data type description
http code content-type response 200
application/json
[{"Number": 25,"Category": "Type 2"}]
Important
Key information Developers need to know to run, mantain and evolve this project.
go version go1.22.1
go mod init
go mod tidy
go get numbers
go run main.go
go run test