HTTP CRUD Sample
This is a sample implementation of CRUD (Create, Read, Update, Delete) in Go.
The sample is using SQLite for persistence and provides the following API endpoints via HTTP:
GET /items
- To retrieve a list of all itemsGET /items/:id
- To retrieve a item using its identifierPOST /items
- To create a new itemPUT /items/:id
- To update an existing item using its identifierDELETE /items/batch
- To delete multiple items providing an array of identifiers as payloadDELETE /items/:id
- To delete an existing item using its identifier
Send data to POST /items
and PUT /items/:id
using the following structure:
{
"name": "item name",
// boolean (either true or false)
"active": true
}
Prerequisites
To run the sample on your local machine, you must have the following software installed:
Running this Sample
Local (spin up
)
To run the sample locally, you must provide @migrations.sql
using the --sqlite
flag to seed the database as shown in the snippet below:
spin build
spin up --sqlite @migrations.sql
Logging component stdio to ".spin/logs/"
Storing default SQLite data to ".spin/sqlite_db.db"
Serving http://127.0.0.1:3000
Available Routes:
http-crud-go-sqlite: http://127.0.0.1:3000 (wildcard)
Fermyon Cloud
You can deploy this sample to Fermyon Cloud following the steps below:
spin cloud login
spin deploy
Uploading http-crud-go-sqlite version 0.1.0 to Fermyon Cloud...
Deploying...
App "http-crud-go-sqlite" accesses a database labeled "default"
Would you like to link an existing database or create a new database?: Create a new database and link the app to it
What would you like to name your database?
What would you like to name your database?
Note: This name is used when managing your database at the account level. The app "http-crud-go-sqlite" will refer to this database by the label "default".
Other apps can use different labels to refer to the same database.: sincere-mulberry
Creating database named 'sincere-mulberry'
Waiting for application to become ready.......... ready
View application: https://http-crud-go-sqlite-jcmbpezb.fermyon.app/
Manage application: https://cloud.fermyon.com/app/http-crud-go-sqlite
spin cloud sqlite execute --database sincere-mulberry @migrations.sql