easyhttp

command module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2026 License: MIT Imports: 6 Imported by: 0

README

easyhttp

easyhttp is a small Go package that provides helper functions to simplify common HTTP request and response handling tasks.

Installation

go get github.com/primekobie/easyhttp

Features

  • JSON helper functions

Example

package main

import (
    "net/http"
    "github.com/primekobie/easyhttp"
)

type User struct {
    ID   int    `json:"id"`
    Name string `json:"name"`
}

func userHandler(w http.ResponseWriter, r *http.Request) {
    user := User{ID: 1, Name: "John Doe"}
    headers := http.Header{}
    headers.Set("X-Custom-Header", "value")

    err := easyhttp.WriteJSON(w, http.StatusOK, user, headers)
    if err != nil {
        // Handle error
    }
}

func updateHandler(w http.ResponseWriter, r *http.Request) {
    var payload struct {  Status string `json:"status"` }
    
    err := easyhttp.ReadJSON(r, &payload) // Read JSON
    if err != nil {
        // Handle error, for example:
        http.Error(w, err.Error(), http.StatusBadRequest)
        return
    }

    // Process the payload...
    easyhttp.WriteJSON(w, http.StatusOK, map[string]string{"status": "updated"}, nil)
}

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