Skip to content

Templates ​

Built-in scenario templates let you generate realistic HTTP requests without manually specifying every parameter.

Categories ​

Basic (6) ​

NameMethodURLDescription
getjsonGET/usersJSON API fetch
postjsonPOST/dataJSON body POST
postformPOST/formForm-encoded POST
loginPOST/loginLogin with username/password
uploadPOST/uploadFile upload (multipart)
bearerGET/meBearer token auth

HTTP Method (5) ​

NameMethodURLDescription
deleteDELETE/resourceREST DELETE
putPUT/resourceREST PUT
patchPATCH/resourceREST PATCH
headHEAD/HEAD request
optionsOPTIONS/OPTIONS request

Recon (4) ​

NameMethodURLDescription
bannerGET/bannerBanner image fetch
redirectGET/Redirect chain (301/302)
errorGET/errorError page (500)
portscanGET/Nmap-style port scan

Extended (5) ​

NameMethodURLDescription
graphqlPOST/graphqlGraphQL query
sseGET/eventsServer-Sent Events stream
websocketGET/wsWebSocket upgrade
grpcwebPOST/grpcgRPC-Web request
chunkedGET/chunkedChunked transfer encoding

Usage ​

CLI ​

bash
# List all templates
request-mock template --list

# Use a template with default URL
request-mock template --name login -f curl

# Override URL
request-mock template --name login --url https://myapp.example.com/auth -f json

# With raw output
request-mock template --name getjson --url https://api.example.com/users -f har --raw

SDK ​

go
spec := mock.GetTemplate("login")
spec.URL = "https://myapp.example.com/auth"
h, _ := mock.GenerateOne(spec)

Template Override Rules ​

When using templates via CLI, the following rules apply:

  • --url overrides the template's default URL
  • --method overrides the template's default method
  • Template headers, cookies, and body are preserved unless you pass overriding flags
  • Template overrides do not modify the template itself; they apply to the copy used for generation

Custom Templates ​

You can register custom templates in the SDK by adding entries to the Templates map:

go
import "github.com/cyberspacesec/request-mock-skills/pkg/mock"

func init() {
    mock.Templates["custom-api"] = &mock.RequestSpec{
        Method: "POST",
        URL:    "https://api.example.com/custom",
        Headers: map[string]string{
            "Content-Type": "application/json",
            "X-API-Key":    "{{API_KEY}}",
        },
        PostData: &mock.PostDataSpec{
            MIMEType: "application/json",
            Text:     `{"action":"custom"}`,
        },
    }
}

Next ​

Released under the MIT License.