Creating Project
Let's dive right in and create a project from scratch, and then run it to see Boneless in action!
For starting we've been thinking of a simple API that uses CRUD.
# First, we need to create go.mod file
$ go mod init bone
# After that let's call command boneless to start a project
# As a default, it was created using SQLite3
$ boneless new
# Here we going to execute all migrations of the `internal/app`
$ boneless migrate app up
# Now, we can use the command `run`
boneless run
__ __ ______ __ ____
/ /_ ____ ____ ___ / / ___ _____ _____ / ____/ / / / _/
/ __ \ / __ \ / __ \ / _ \ / / / _ \ / ___/ / ___/ / / / / / /
/ /_/ // /_/ / / / / // __/ / / / __/ (__ ) (__ ) / /___ / /___ _/ /
/_.___/ \____/ /_/ /_/ \___/ /_/ \___/ /____/ /____/ \____/ /_____//___/
running...
PID: <process-id>
BFF listener available on 127.0.0.1:8090
┌───────────────────────────────────────────────────┐
│ Fiber v2.48.0 │
│ http://127.0.0.1:8090 │
│ │
│ Handlers ............. 6 Processes ........... 1 │
│ Prefork ....... Disabled PID ............. 40506 │
└───────────────────────────────────────────────────┘
╭───────────────────────────────────────────────────╮
│ app : main │
│ deployment : <uuid> │
╰───────────────────────────────────────────────────╯
Wow, here we created your first app using Boneless. Now, we can be using it, let's use cURL for testing.
# Get All Examples
$ curl --location --request GET 'http://127.0.0.1:8090/examples'
# returns empty because we haven't data yet
# []
# Create an Example
$ curl --location --request POST 'http://127.0.0.1:8090/examples/' \
--header 'Content-Type: application/json' \
--data-raw '{
"message": "Hello everyone"
}'
# After you created anything we can get an example just
# but you need to know the ID for it
$ curl --location --request GET 'http://127.0.0.1:8090/examples/:id'
# example data
{
"id": 2104895800, # id is random
"created_at": "2023-07-20T03:22:37.289-03:00",
"message": "Hello everyone"
}
That's all folks!
Last updated