Templates
Built-in scenario templates let you generate realistic HTTP requests without manually specifying every parameter.
Categories
Basic (6)
| Name | Method | URL | Description |
|---|---|---|---|
getjson | GET | /users | JSON API fetch |
postjson | POST | /data | JSON body POST |
postform | POST | /form | Form-encoded POST |
login | POST | /login | Login with username/password |
upload | POST | /upload | File upload (multipart) |
bearer | GET | /me | Bearer token auth |
HTTP Method (5)
| Name | Method | URL | Description |
|---|---|---|---|
delete | DELETE | /resource | REST DELETE |
put | PUT | /resource | REST PUT |
patch | PATCH | /resource | REST PATCH |
head | HEAD | / | HEAD request |
options | OPTIONS | / | OPTIONS request |
Recon (4)
| Name | Method | URL | Description |
|---|---|---|---|
banner | GET | /banner | Banner image fetch |
redirect | GET | / | Redirect chain (301/302) |
error | GET | /error | Error page (500) |
portscan | GET | / | Nmap-style port scan |
Extended (5)
| Name | Method | URL | Description |
|---|---|---|---|
graphql | POST | /graphql | GraphQL query |
sse | GET | /events | Server-Sent Events stream |
websocket | GET | /ws | WebSocket upgrade |
grpcweb | POST | /grpc | gRPC-Web request |
chunked | GET | /chunked | Chunked 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 --rawSDK
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:
--urloverrides the template's default URL--methodoverrides 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
- CLI: template & batch — template CLI usage
- SDK Guide — using templates in Go code
- Transforms — combine with transforms for variation