simple-webserver-with-reactJS

command
v0.0.0-...-a2a1f02 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 1, 2020 License: MIT Imports: 5 Imported by: 0

README

simple-webserver-with-reactJS example

*** THE REPO IS UNDER CONSTRUCTION - CHECK BACK SOON ***

TBD.

GitHub Webpage

PREREQUISITES

go get -u -v github.com/gorilla/mux
go get -u -v github.com/sirupsen/logrus

SOFTWARE STACK

  • GUI golang net/http package and ReactJS
  • Routing & REST API framework golang gorilla/mux package
  • Backend golang
  • Database N/A

HOW IT WORKS

HOW IT WORKS

The ???? package lets us map request paths to functions.

  1. Set which IP and port you would like to listen on,

    log.Fatal(http.ListenAndServe("127.0.0.1:1234", nil))
    
  2. When a request is made for a particular URL kick off your function,

    http.HandleFunc("/jeff", jeffHandler)
    
  3. Create your handler function jeffHandler,

    func jeffHandler(res http.ResponseWriter, req *http.Request) {
        fmt.Printf("req is %+v\n\n", req.URL)
        io.WriteString(res, "hello, Jeff!\n")
    }
    

This illustration may help,

IMAGE - simple-webserver-with-reactJS - IMAGE

RUN

go run simple-webserver.go

Press return to exit.

You can interact with the web server many different ways.

USING A BROWSER

http://127.0.0.1:1234/

http://127.0.0.1:1234/jeff

http://127.0.0.1:1234/monkey

USING HTTPIE

In another terminal, use a CLI http client like httpie and you can do the following,

http localhost:1234
http localhost:1234/jeff
http localhost:1234/monkey

Or you can use the IP Address,

http 127.0.0.1:1234
http 127.0.0.1:1234/jeff
http 127.0.0.1:1234/monkey
USING CURL

Or you can use curl,

curl 127.0.0.1:1234
curl 127.0.0.1:1234/jeff
curl 127.0.0.1:1234/monkey

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL