This project is as the repo title stated, a simple http server made in golang. Just compile it or run it using the usual command. Running the executable without any commands will print a summarize usage information.
The program accepts one main subcommand: serve
. It's used to create a HTTP listener on the localhost port 80.
You can specify a --address ADDRESS:PORT
argument to give the server an address and port of your choosing. The ADDRESS
must be an IPv4 address or the alias localhost
which will be expanded to the loopback address.
The server uses a JSON file-based database for its non-volatile storage mechanism.
It will create a default file.json on the current directory for its runtime storage,
and will insert one entry just for keep sake. The argument --file JSON_PATH
can be specified to use a custom json file.
The server supports the following API:
- PUT /create-data - Creates data
- GET /get-data - Get the data
- POST /update-data - Updates the data
- DELETE /delete-data - Deletes the data
The create endpoint accepts two query parameters: name
and value
. The name
parameter defines the name of the entry,
and it is required. The value
parameter is optional, and if its not set, the entry value will be an empty string.
Creates an entry named "b" with the value "hello"
The get endpoint accepts two query parameters: id
and name
, but only one of them must be used at a time. You can get an
entry by id
or by name
. Setting the id
to -1
will return all entries.
Retreive the entry named "b". Notice how a single entry is wrapped in a collection?
Retreive all entries. Both entry "b" and "a" is present on the response message.
The update endpoint accepts two query parameters: name
and value
. The name
parameter specifies the target entry to modify,
and an optional value
parameter specifies new value. No value
means empty string.. same deal as create API :)
Sets the value of entry "b" to "goodbye"
The delete endpoint basically works like the get API, where you can either delete by id
or name
. Setting the id
to -1 will
delete all entries, setting it to null.
Deletes all entry by setting id=-1
The example pictures above contains all the expected succesful response status code for each API. Malformed queries will
return a 400
response status. If for whatever reason when synchronizing/writing dirty runtime data into the JSON file failed,
a response status of 500
will be returned.