ObjApiEdit extends the ObjApi class to provide specialized functionality for editing and exporting API configurations, specifically designed to export webhook configurations to Insomnia REST client format.
Module: factory.core/ObjApiEdit.py
Inherits from: ObjApi.ObjApi
Test file: resource.test/pytests/factory.core/test_ObjApiEdit.py
This module enables developers to:
patch_param()class WebhookMethod(StrEnum):
GET = "GET"
POST = "POST"
PUT = "PUT"
DELETE = "DELETE"
PATCH = "PATCH"
class MimeType(StrEnum):
APPLICATION_JSON = "application/json"
APPLICATION_XML = "application/xml"
TEXT_PLAIN = "text/plain"
FORM_URLENCODED = "application/x-www-form-urlencoded"
MULTIPART_FORM_DATA = "multipart/form-data"
export_webhooks_to_insomnia(service_code: str) -> strExports all active webhooks associated with a given service code to Insomnia format.
Parameters:
service_code (str): The service code to filter webhooks byReturns:
Process Flow:
Export Structure:
{
"_type": "export",
"__export_format": 4,
"__export_date": "ISO timestamp",
"__export_source": "ObjApiEdit",
"resources": [
{
"_type": "request_group",
"name": "Webhooks - {service_code}",
...
},
{
"_type": "request",
"method": "POST",
"url": "...",
...
}
]
}
export-insomnia-webhookspython factory.core/ObjApiEdit.py export-insomnia-webhooks <service_code>
Arguments:
service_code (required): The service code to filter webhooks for exportExample:
python factory.core/ObjApiEdit.py export-insomnia-webhooks MYSERVICE
def_webhook
select_webhooks_by_service_codedef_webhook_parameters
select_webhook_parametersfrom ObjApiEdit import ObjApiEdit
# Create instance
api = ObjApiEdit()
# Export webhooks for a service
insomnia_json = api.export_webhooks_to_insomnia("CUSTOMER_SERVICE")
# Save to file
with open("customer_service_webhooks.json", "w") as f:
f.write(insomnia_json)
The module has comprehensive test coverage including:
| Test Case | Description | Status |
|---|---|---|
test_export_no_webhooks |
Validates export with empty webhook list | ✓ |
test_export_single_webhook |
Tests single POST webhook with JSON body | ✓ |
test_export_get_request_with_params |
Tests GET webhook with URL parameters | ✓ |
test_export_webhook_with_api_key |
Tests API Key authentication export | ✓ |
Test file location: resource.test/pytests/factory.core/test_ObjApiEdit.py
Run tests:
pytest resource.test/pytests/factory.core/test_ObjApiEdit.py -v
Headers stored in the database use pipe-separated format:
Content-Type: application/json|X-Custom-Header: value|Authorization: Bearer token
Converted to Insomnia format:
[
{"name": "Content-Type", "value": "application/json"},
{"name": "X-Custom-Header", "value": "value"},
{"name": "Authorization", "value": "Bearer token"}
]
The module uses patch_param() method to replace placeholders in:
https://api.example.com/{{ environment }}/endpoint){"id": "{{ param_id }}"})json - JSON serializationdatetime - Timestamp generationtyper - CLI interfaceObjApi - Parent classObjConstants - MIME type constantsThe module uses YAML queries defined in the ObjApi configuration:
select_webhooks_by_service_code: Retrieves webhooks by serviceselect_webhook_parameters: Retrieves webhook parametersObjApi.py - Parent class providing API operationsObjWorkflow.py - Workflow engine that may invoke webhooksServeWebHook.py - Service that handles incoming webhook requests