Skip to content

CTRLRLTY/golang-simple-http-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TOO LAZY TO READ!!!!!!!!!!!

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

API: PUT /create-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.

Example creating an entry

Creates an entry named "b" with the value "hello"

create1

API: GET /get-data

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.

Example of getting an entry by name

Retreive the entry named "b". Notice how a single entry is wrapped in a collection?

get1

Example of getting all entries

Retreive all entries. Both entry "b" and "a" is present on the response message.

get2

API: POST /update-data

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 :)

Example of updating an entry by name

Sets the value of entry "b" to "goodbye"

update1

API: DELETE /delete-data

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.

Example of deleting all entries

Deletes all entry by setting id=-1

delete1

Response status

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.

^^^ The code here is under no license, so go nuts ^^^

About

SIMPLE HTTP SERVER MADE IN GOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages