> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# HCMockAddMock

> HCMockAddMock

# HCMockAddMock

Configures libHttpClient to return mock response instead of making a network call when HCHttpCallPerformAsync() is called.

## Syntax

```cpp theme={null}
HRESULT HCMockAddMock(  
         HCMockCallHandle call,  
         const char* method,  
         const char* url,  
         const uint8_t* requestBodyBytes,  
         uint32_t requestBodySize  
)  
```

### Parameters

*call*   \_In\_\
Type: HCMockCallHandle

This HC\_MOCK\_CALL\_HANDLE that represents the mock that has been configured accordingly using HCMockResponseSet\*()

*method*   \_In\_opt\_z\_\
Type: char\*

If you want the mock to only apply to a specific URL, pass in a UTF-8 encoded method and URL.

*url*   \_In\_opt\_z\_\
Type: char\*

If you want the mock to only apply to a specific URL, pass in a UTF-8 encoded method and URL.

*requestBodyBytes*   \_In\_reads\_bytes\_opt\_(requestBodySize)\
Type: uint8\_t\*

If you want the mock to only apply to a specific URL & request string, pass in a method, URL and a string body.

*requestBodySize*   \_In\_\
Type: uint32\_t

The size of requestBodyBytes in bytes.

### Return value

Type: HRESULT

Result code for this API operation. Possible values are S\_OK, E\_INVALIDARG, E\_OUTOFMEMORY, or E\_FAIL.

## Remarks

To define a mock response, create a new HC\_MOCK\_CALL\_HANDLE with HCMockCallCreate() that represents the mock. Then use HCMockResponseSet\*() to set the mock response. By default, the mock response will be returned for all HTTP calls. If you want the mock to only apply to a specific URL, pass in a URL. If you want the mock to only apply to a specific URL & request body, pass in a URL and a body. Once the HC\_MOCK\_CALL\_HANDLE is configured as desired, add the mock to the system by calling HCMockAddMock(). You can set multiple active mock responses by calling HCMockAddMock() multiple times with a set of mock responses. If the HTTP call matches against a set mock responses, they will be executed in order for each subsequent call to HCHttpCallPerformAsync(). When the last matching mock response is hit, the last matching mock response will be repeated on each subsequent call to HCHttpCallPerformAsync().

## Requirements

**Header:** mock.h

**Library:** libHttpClient.GDK.lib

## See also

[mock](/reference/live/httpclient/mock/mock_members)


## Related topics

- [HCMockClearMocks](/reference/live/httpclient/mock/functions/hcmockclearmocks.md)
- [HCMockCallCreate](/reference/live/httpclient/mock/functions/hcmockcallcreate.md)
- [HCMockSetMockMatchedCallback](/reference/live/httpclient/mock/functions/hcmocksetmockmatchedcallback.md)
- [HCMockRemoveMock](/reference/live/httpclient/mock/functions/hcmockremovemock.md)
- [HCMockCallCloseHandle](/reference/live/httpclient/mock/functions/hcmockcallclosehandle.md)
