Add v1 JSON API endpoints alongside existing HTML endpoints:
- POST /v1/endpoints/{id}/requests: Capture JSON request
- GET /v1/endpoints/{id}/requests: List or search requests
- POST /v1/endpoints/{id}/requests/{reqId}/replay: Replay captured request
- PUT /v1/endpoints/{id}/mock: Set mock configuration
- GET /v1/endpoints/{id}/openapi.json: OpenAPI 3.1 specification
Add SearchRequests to Repository interface and implement simple LIKE search.
Write integration tests for all v1 endpoints. Ensure backward compatibility
with existing HTML endpoints.
Co-Authored-By: Paperclip <noreply@paperclip.ing>
44 lines
1.4 KiB
Go
44 lines
1.4 KiB
Go
package store
|
|
|
|
import "context"
|
|
|
|
type Endpoint struct {
|
|
ID string `json:"id"`
|
|
URL string `json:"url"`
|
|
CreatedAt string `json:"created_at"`
|
|
UpdatedAt string `json:"updated_at"`
|
|
}
|
|
|
|
type Request struct {
|
|
ID string `json:"id"`
|
|
EndpointID string `json:"endpoint_id"`
|
|
Method string `json:"method"`
|
|
Path string `json:"path"`
|
|
Headers string `json:"headers"`
|
|
Query string `json:"query"`
|
|
Body []byte `json:"body"`
|
|
CreatedAt string `json:"created_at"`
|
|
}
|
|
|
|
// MockConfig holds the mock response configuration for an endpoint.
|
|
type MockConfig struct {
|
|
EndpointID string `json:"endpoint_id"`
|
|
Status int `json:"status"`
|
|
Headers map[string]string `json:"headers"`
|
|
Body []byte `json:"body"`
|
|
}
|
|
|
|
type Repository interface {
|
|
CreateEndpoint(ctx context.Context, url string) (*Endpoint, error)
|
|
GetEndpoint(ctx context.Context, id string) (*Endpoint, error)
|
|
AppendRequest(ctx context.Context, endpointID string, req *Request) error
|
|
GetRequest(ctx context.Context, id string) (*Request, error)
|
|
ListRequests(ctx context.Context, endpointID string, limit int) ([]*Request, error)
|
|
SearchRequests(ctx context.Context, endpointID string, query string, limit int) ([]*Request, error)
|
|
GetMock(ctx context.Context, endpointID string) (*MockConfig, error)
|
|
SetMock(ctx context.Context, mock *MockConfig) error
|
|
Close() error
|
|
}
|
|
|
|
var _ Repository = (*sqliteRepo)(nil)
|