https://github.com/bndrmrtn/playword
https://github.com/bndrmrtn/playword
Last synced: over 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/bndrmrtn/playword
- Owner: bndrmrtn
- Created: 2023-10-11T18:09:06.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-10-15T12:29:05.000Z (almost 3 years ago)
- Last Synced: 2025-02-07T06:14:10.961Z (over 1 year ago)
- Language: Go
- Size: 13.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# PlayWord API with Go Fiber
This is my first project with Go and Fiber. It's an API for a simple app.
It contains 2 endpoints, a `GET` and a `POST`.
| Method | Resource |
|--------|-----------|
| `GET` | /api/game |
| `POST` | /api/game |
Every endpoint returns a `JSON` response.
### `GET` endpoint
This endpoint returns a `JSON` response like this:
```json
{
"data": {
"letters":["w","r","p","e","o"],
"length":5,
"max_trials":3,
"trials":0,
"guessed":0,
"expiration":"2023-10-15T14:01:55.2868383+02:00"
},
"status":{
"code":200,
"message":"OK"
}
}
```
So, it contains a `status` for the status, and `data`
for the game data, it contains the `letters` in an array
and the letters are mixed. The `length` is the length of the word.
The `max_trials` is the maximum number of trials for the user to guess the word.
The `trials` is the current trials, and the `guessed` is how many words the user guessed.
An `expiration` is the expiration time to guess the word (currently not implemented).
### `POST` endpoint
For the `POST` endpoint you have to send a
`JSON` request body with the following parameter:
```json
{
"guess": "power"
}
```
Then the server will return a `JSON` response.
#### When the word is successfully guessed
```json
{
"valid": true,
"trials": 1,
"endgame": false,
"msg": {
"type": "success",
"text": "Congratulation you\nguessed the word! :D"
}
}
```
#### Otherwise
```json
{
"valid": false,
"trials": 2,
"endgame": false,
"msg": {
"type": "error",
"text": "No problem! You have 1 more trial"
}
}
```
### The projects structure
```tree
📦 Project
📂 database
📂 handlers
📂 types
📂 helpers
📂 http
📂 session
📂 models
📂 routes
📜 main.go
```