Skip to content
This repository was archived by the owner on Oct 6, 2025. It is now read-only.

udan-jayanith/HTTP-V1.1

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HTTPNav

HTTPNav is a lightweight HTTP/1.1 Go package designed to simplify HTTP request and response handling. It provides custom encoders and decoders to streamline working with HTTP headers and payloads.

Note: HTTPNav does not support HTTPS.

Installation

To install HTTPNav, use go get:

go get github.com/udan-jayanith/HTTPNav

Then, import it into your Go code:

import HTTPNav "github.com/udan-jayanith/HTTPNav"

Usage

Server

server contains server data and logic.

GetServer

HTTPNav.GetServer()

GetServer() Function returns a new server.

HandelFunc

HandelFunc takes HTTPRequestMethod, requestTarget and a handler. If requests httpMethod and requestTarget matches the handler handler will execute.

Ex:

server.HandleFunc(httpNav.Get, "/", func(response *httpNav.HTTPResponse, request *httpNav.HTTPRequest) {
		response.Write([]byte("Hello world. /"))
        //Write send a response back to the client.
})

StartServer

StartServer(":8080")

StartServer start the server(starts listing to incoming requests).

HTTPRequest

Parses the HTTP request and store in it. Then pointer to the HTTPRequest is passed to matching HandleFunc()

GetBodyAsBytes

This return Body as a slice of bytes. If Content-Length header is not included in the header GetBodyAsBytes() returns ContentLengthHeaderNotFound.

bodyBty, err := request.GetBodyAsBytes()

GetBodyAsJson

var v map[string]any
err := request.GetBodyAsJson(&v)

GetBodyAsJson parses the JSON-encoded data and stores the result in the value pointed to by v. If Content-Type is not in the header GetBodyAsJson returns ContentTypeHeaderNotFound. Else if Content-Type != "application/json" GetBodyAsJson returns InvalidContentType. It uses GetBodyAsBytes in underlying layer.

To see other functionalities see HTTP Go Doc or simply see source code.

License

This project is licensed under the MIT License. See the LICENSE.md file for details.

About

This Go library is a HTTP v1.1 library form scratch build over TCP.

Topics

Resources

License

BSD-3-Clause, MIT licenses found

Licenses found

BSD-3-Clause
LICENSE
MIT
LICENSE.md

Stars

Watchers

Forks

Contributors

Languages