this is a sample RESTful API written in go.
First you need to Install Docker
then run this command to run a postgres container which maps port 5432 to localhost:5432
docker run --name pg -p 5432:5432 -d postgres
then this command will give you a psql shell with the appropriate user:
docker exec -it pg psql postgres postgres
after database is created, run this command to create a users table
CREATE TABLE users (
id SERIAL PRIMARY KEY NOT NULL,
firstName VARCHAR(255) NOT NULL,
LastName VARCHAR(255) NOT NULL,
email VARCHAR(255) NOT NULL,
createdAt TIMESTAMP NOT NULL DEFAULT NOW(),
updatedAt TIMESTAMP NOT NULL DEFAULT NOW()
);
You can execute the binary file directly by typing
./main
this will make available the following endpoints:
returns a JSON object with: a greeting message
returns a JSON object with: a healthcheck status message and timestamp
POST => http://localhost:8080/users
returns a JSON object with: a confirmation message and status code
GET => http://localhost:8080/users
returns a JSON array with: user objects
returns a JSON object with: user properties
returns a JSON object with: a confirmation message and status code
DELETE => http://localhost:8080/users/:id
returns a JSON object with: a confirmation message and status code
first create this table
CREATE TABLE btcoffers (
ID SERIAL PRIMARY KEY NOT NULL,
Title VARCHAR(255) NOT NULL,
Trader VARCHAR(255) NOT NULL,
Bank VARCHAR(255) NOT NULL,
Currency VARCHAR(255) NOT NULL,
Reputation SMALLINT,
Price FLOAT,
Min FLOAT,
Max FLOAT,
Index SMALLINT NOT NULL,
CreatedAt TIMESTAMP NOT NULL DEFAULT NOW(),
UpdatedAt TIMESTAMP NOT NULL DEFAULT NOW()
);