Modules@robinpath/proxy
proxy

@robinpath/proxy

0.1.4Node.jsPublic

HTTP proxy and request forwarding module using Node.js built-in http module. Supports creating proxy servers, URL rewriting, header manipulation, request and response interception, round-robin load balancing, and health checking. No external dependencies required.

Proxy

HTTP proxy and request forwarding module using Node.js built-in http module. Supports creating proxy servers, URL rewriting, header manipulation, request and response interception, round-robin load balancing, and health checking. No external dependencies required.

Package: @robinpath/proxy | Category: Web | Type: Utility

Authentication

No authentication required. All functions are available immediately.

Use Cases

Use the proxy module when you need to:

  • Forward a single HTTP request to a target server and return the response -- Use proxy.forward to perform this operation
  • Create a new HTTP proxy server instance -- Use proxy.create to perform this operation
  • Start a proxy server and begin listening for requests -- Use proxy.start to perform this operation
  • Stop a running proxy server and clean up resources -- Use proxy.stop to perform this operation
  • Add a URL rewrite rule to transform incoming request paths -- Use proxy.rewrite to perform this operation

Quick Reference

FunctionDescriptionReturns
forwardForward a single HTTP request to a target server and return the responseobject
createCreate a new HTTP proxy server instanceobject
startStart a proxy server and begin listening for requestsobject
stopStop a running proxy server and clean up resourcesobject
rewriteAdd a URL rewrite rule to transform incoming request pathsobject
addHeaderAdd a header to all proxied responsesobject
removeHeaderRemove a header from all proxied responsesobject
onRequestRegister an interceptor function for incoming requestsobject
onResponseRegister an interceptor function for proxy responsesobject
balanceConfigure round-robin load balancing across multiple target serversobject
healthCheck the health of a target server by sending a HEAD requestobject
listList all active proxy server instances and their configurationsobject
statsGet statistics for a proxy server including request count, errors, and uptimeobject

Functions

forward

Forward a single HTTP request to a target server and return the response

Module: proxy | Returns: object -- API response.

proxy.forward
ParameterTypeRequiredDescription
targetUrlstringNoTarget server URL to forward to
methodstringNoHTTP method (GET, POST, etc.)
pathstringNoRequest path (default: /)
headersobjectNoRequest headers
bodystringNoRequest body

create

Create a new HTTP proxy server instance

Module: proxy | Returns: object -- API response.

proxy.create
ParameterTypeRequiredDescription
idstringNoProxy identifier
targetstringNoDefault target URL to proxy requests to
portnumberNoPort to listen on (default: 8080)

start

Start a proxy server and begin listening for requests

Module: proxy | Returns: object -- API response.

proxy.start
ParameterTypeRequiredDescription
idstringNoProxy identifier

stop

Stop a running proxy server and clean up resources

Module: proxy | Returns: object -- API response.

proxy.stop
ParameterTypeRequiredDescription
idstringNoProxy identifier

rewrite

Add a URL rewrite rule to transform incoming request paths

Module: proxy | Returns: object -- API response.

proxy.rewrite
ParameterTypeRequiredDescription
idstringNoProxy identifier
patternstringNoRegex pattern to match in the URL
replacementstringNoReplacement string

addHeader

Add a header to all proxied responses

Module: proxy | Returns: object -- API response.

proxy.addHeader
ParameterTypeRequiredDescription
idstringNoProxy identifier
namestringNoHeader name
valuestringNoHeader value

removeHeader

Remove a header from all proxied responses

Module: proxy | Returns: object -- API response.

proxy.removeHeader
ParameterTypeRequiredDescription
idstringNoProxy identifier
namestringNoHeader name to remove

onRequest

Register an interceptor function for incoming requests

Module: proxy | Returns: object -- API response.

proxy.onRequest
ParameterTypeRequiredDescription
idstringNoProxy identifier
callbackstringNoInterceptor function receiving (req)

onResponse

Register an interceptor function for proxy responses

Module: proxy | Returns: object -- API response.

proxy.onResponse
ParameterTypeRequiredDescription
idstringNoProxy identifier
callbackstringNoInterceptor function receiving (proxyRes, res)

balance

Configure round-robin load balancing across multiple target servers

Module: proxy | Returns: object -- API response.

proxy.balance
ParameterTypeRequiredDescription
idstringNoProxy identifier
targetsarrayNoArray of target URLs for load balancing

health

Check the health of a target server by sending a HEAD request

Module: proxy | Returns: object -- API response.

proxy.health
ParameterTypeRequiredDescription
targetUrlstringNoTarget URL to check
timeoutnumberNoTimeout in milliseconds (default: 5000)

list

List all active proxy server instances and their configurations

Module: proxy | Returns: object -- API response.

proxy.list
ParameterTypeRequiredDescription
(none)NoCall with no arguments

stats

Get statistics for a proxy server including request count, errors, and uptime

Module: proxy | Returns: object -- API response.

proxy.stats
ParameterTypeRequiredDescription
idstringNoProxy identifier

Error Handling

All functions throw on failure. Common errors:

ErrorCause
Target URL is required.Check the error message for details
Pattern is required.Check the error message for details
Replacement is required.Check the error message for details
Header name is required.Check the error message for details
Header value is required.Check the error message for details
A callback function is required.Check the error message for details
An array of target URLs is required.Check the error message for details
Proxy "..." not found. Call create() first.Check the error message for details
@desc "Forward and validate result"
do
  set $result as proxy.forward
  if $result != null
    print "Success"
  else
    print "No result"
  end
enddo

Recipes

1. List and iterate

Retrieve all items and loop through them.

@desc "List and iterate results"
do
  set $result as proxy.list
  each $item in $result
    print $item
  end
enddo

2. Create a new item with create

Create a new resource and capture the result.

set $result as proxy.create
print "Created: " + $result

3. Check before creating

List existing items and only create if needed.

@desc "List and create"
do
  set $existing as proxy.list
  if $existing == null
    proxy.create
    print "Item created"
  else
    print "Item already exists"
  end
enddo

4. Multi-step Proxy workflow

Chain multiple proxy operations together.

@desc "Forward, create, and more"
do
  set $r_forward as proxy.forward
  set $r_create as proxy.create
  set $r_start as proxy.start
  print "All operations complete"
enddo

5. Safe forward with validation

Check results before proceeding.

@desc "Forward and validate result"
do
  set $result as proxy.forward
  if $result != null
    print "Success: " + $result
  else
    print "Operation returned no data"
  end
enddo

Related Modules

  • json -- JSON module for complementary functionality

Versions (3)

VersionTagPublished
0.1.4latest21 days ago
0.1.321 days ago
0.1.21 months ago
Install
$ robinpath add @robinpath/proxy

Collaborators

Dumitru Balaban
Dumitru Balaban
@dumitru
View all @robinpath modules
Version0.1.4
LicenseMIT
Unpacked Size13.2 KB
Versions3
Weekly Downloads21
Total Downloads21
Stars0
Last Publish21 days ago
Created1 months ago

Keywords

Category

web