http

package
v0.15.1 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package http provides Node.js http module equivalents for transpiled TypeScript code.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get

func Get(url string) (*http.Response, error)

Get performs an HTTP GET request (simplified http.get).

func JSONParse

func JSONParse(s string) (any, error)

JSONParse parses a JSON string.

func JSONStringify

func JSONStringify(v any) string

JSONStringify converts a value to a JSON string.

func Request

func Request(url string, opts RequestOptions) (*http.Response, error)

Request performs an HTTP request with options.

Types

type IncomingMessage

type IncomingMessage struct {
	Method  string
	URL     string
	Headers http.Header
	// contains filtered or unexported fields
}

IncomingMessage wraps an HTTP request (Node.js http.IncomingMessage).

func (*IncomingMessage) Body

func (m *IncomingMessage) Body() string

Body returns the request body as a string.

type RequestOptions

type RequestOptions struct {
	Method  string
	Headers map[string]string
	Body    string
}

RequestOptions holds options for http.request.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server wraps a Go HTTP server with Node.js-like API.

func CreateServer

func CreateServer(handler func(req *IncomingMessage, res *ServerResponse)) *Server

CreateServer creates an HTTP server with the given handler.

func (*Server) Close

func (s *Server) Close() error

Close stops the server.

func (*Server) Listen

func (s *Server) Listen(port int, callback ...func()) error

Listen starts the server on the given port.

type ServerResponse

type ServerResponse struct {
	// contains filtered or unexported fields
}

ServerResponse wraps an HTTP response writer (Node.js http.ServerResponse).

func (*ServerResponse) End

func (r *ServerResponse) End(data ...string)

End finishes the response, optionally writing data.

func (*ServerResponse) SetHeader

func (r *ServerResponse) SetHeader(key, value string)

SetHeader sets a response header.

func (*ServerResponse) Write

func (r *ServerResponse) Write(data string)

Write writes data to the response.

func (*ServerResponse) WriteHead

func (r *ServerResponse) WriteHead(statusCode int, headers ...map[string]string)

WriteHead sets the status code and headers.

Jump to

Keyboard shortcuts

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