Temporary cache data using POST method #368

Closed
opened 2025-12-29 15:22:00 +01:00 by adam · 11 comments
Owner

Originally created by @devmariodiaz on GitHub (Oct 14, 2021).

Hello Stef,

Hoping that everything is doing well.

I have a question: WireMock is able to store temporary cache when we are using POST or any operation?

Originally created by @devmariodiaz on GitHub (Oct 14, 2021). Hello Stef, Hoping that everything is doing well. I have a question: WireMock is able to store temporary cache when we are using POST or any operation?
adam added the question label 2025-12-29 15:22:00 +01:00
adam closed this issue 2025-12-29 15:22:00 +01:00
Author
Owner

@devmariodiaz commented on GitHub (Oct 19, 2021):

Hello Stef, hopping that you are doing well

I would like ask you if Is there any update about this feature?

@devmariodiaz commented on GitHub (Oct 19, 2021): Hello Stef, hopping that you are doing well I would like ask you if Is there any update about this feature?
Author
Owner

@StefH commented on GitHub (Oct 19, 2021):

Hello Mario,
I'm not sure I fully understand your request.

Can you provide an example / use-case scenario?

@StefH commented on GitHub (Oct 19, 2021): Hello Mario, I'm not sure I fully understand your request. Can you provide an example / use-case scenario?
Author
Owner

@devmariodiaz commented on GitHub (Oct 19, 2021):

Hello Stef, Thanks for always your quick answers.

For example, I will send some data using POST/PUT or another HTTP method, I want that this data can be stored in a kind of cache for a determined time inside a based WireMock solution.

i. e:

I will send the data as follows:

{
    "firstName": "Mario",
    "birthDate": "01-01-2000",
   .
   .
   .
   "insertedAt": "01-01-2020"
}

To for example this endpoint:
POST /someEndpoint/customer

I want to store this data temporarily, for one day, to be found after.

@devmariodiaz commented on GitHub (Oct 19, 2021): Hello Stef, Thanks for always your quick answers. For example, I will send some data using POST/PUT or another HTTP method, I want that this data can be stored in a kind of cache for a determined time inside a based WireMock solution. i. e: I will send the data as follows: ``` { "firstName": "Mario", "birthDate": "01-01-2000", . . . "insertedAt": "01-01-2020" } ``` To for example this endpoint: POST /someEndpoint/customer I want to store this data temporarily, for one day, to be found after.
Author
Owner

@StefH commented on GitHub (Oct 20, 2021):

Hello Mario,

In that case, there should be an option to provide the start-time, end-time or expiration-time.

Proposal:
In the Mapping you can provide the start-time and end-time when this mapping should be used

{
    "Guid": "dae02a0d-8a33-46ed-aab0-afbecc8643e3",
    "Start": "2021-10-20T05:25:40",
    "End": "2022-01-01T01:01:01",
    ...
  • If "Start" is omitted, the current DateTime is used
  • If "End" is omitted, there is no end-time

And you can also only provide the TTL / TimeToLive

{
    "Guid": "dae02a0d-8a33-46ed-aab0-afbecc8643e3",
    "TTL": 3600,
    ...

Would this work for you?

@StefH commented on GitHub (Oct 20, 2021): Hello Mario, In that case, there should be an option to provide the start-time, end-time or expiration-time. Proposal: In the Mapping you can provide the start-time and end-time when this mapping should be used ``` js { "Guid": "dae02a0d-8a33-46ed-aab0-afbecc8643e3", "Start": "2021-10-20T05:25:40", "End": "2022-01-01T01:01:01", ... ``` - If "Start" is omitted, the current DateTime is used - If "End" is omitted, there is no end-time And you can also only provide the TTL / TimeToLive ``` js { "Guid": "dae02a0d-8a33-46ed-aab0-afbecc8643e3", "TTL": 3600, ... ``` Would this work for you?
Author
Owner

@StefH commented on GitHub (Oct 20, 2021):

@devmariodiaz
I've created a new preview version : 1.4.24-ci-15508.

Use TimeSettings -->

{
    "Guid": "dae02a0d-8a33-46ed-aab0-afbecc8643e3",
    "TimeSettings": {
      "Start": "2021-10-20T05:25:40",
      "End": "2022-01-01T01:01:01"
    }
    ...
@StefH commented on GitHub (Oct 20, 2021): @devmariodiaz I've created a new preview version : `1.4.24-ci-15508`. Use **TimeSettings** --> ``` js { "Guid": "dae02a0d-8a33-46ed-aab0-afbecc8643e3", "TimeSettings": { "Start": "2021-10-20T05:25:40", "End": "2022-01-01T01:01:01" } ... ```
Author
Owner

@devmariodiaz commented on GitHub (Oct 20, 2021):

Hello Stef,

Thanks for your always quick answers.

I have been testing this preview, but, I don't understood how works this implemented feature.

i. e: I used this canned data JSON:

{
  "TimeSettings": {
    "Start": "2021-10-20T14:49:00",
    "End": "2021-10-20T14:55:01"
  },
  "Title": "Post Request",
  "Request": {
    "Path": {
      "Matchers": [
        {
          "Name": "WildcardMatcher",
          "Pattern": "/*/postnames",
          "IgnoreCase": false
        }
      ]
    },
    "Methods": [
      "POST"
    ],
    "Body": {
      "Matcher": {
        "Name": "JsonMatcher",
        "Pattern": { "name": "Person Name POST" }
      }
    }
  },
  "Response": {
    "StatusCode": 206,
    "BodyAsFile": "myJson.json",
    "Headers": {
      "Content-Type": "application/json; charset=UTF-8",
      "Content-Length": "105",
      "Date": "Wed, 06 Oct 2021 14:41:14 GMT"
    }
  }
}
@devmariodiaz commented on GitHub (Oct 20, 2021): Hello Stef, Thanks for your always quick answers. I have been testing this preview, but, I don't understood how works this implemented feature. i. e: I used this canned data JSON: ``` { "TimeSettings": { "Start": "2021-10-20T14:49:00", "End": "2021-10-20T14:55:01" }, "Title": "Post Request", "Request": { "Path": { "Matchers": [ { "Name": "WildcardMatcher", "Pattern": "/*/postnames", "IgnoreCase": false } ] }, "Methods": [ "POST" ], "Body": { "Matcher": { "Name": "JsonMatcher", "Pattern": { "name": "Person Name POST" } } } }, "Response": { "StatusCode": 206, "BodyAsFile": "myJson.json", "Headers": { "Content-Type": "application/json; charset=UTF-8", "Content-Length": "105", "Date": "Wed, 06 Oct 2021 14:41:14 GMT" } } } ```
Author
Owner

@StefH commented on GitHub (Oct 21, 2021):

@devmariodiaz
To make sure you have the correct version, there is a new vetrsion : 1.4.24-ci-15516. Please try that.

In your example, when you add that mapping and send a POST request, WireMock.Net will return a 404 because now (2021 21 oktober) does not fall in the Start and End range.

@StefH commented on GitHub (Oct 21, 2021): @devmariodiaz To make sure you have the correct version, there is a new vetrsion : `1.4.24-ci-15516`. Please try that. In your example, when you add that mapping and send a POST request, WireMock.Net will return a 404 because now (2021 21 oktober) does not fall in the Start and End range.
Author
Owner

@AndresGMD commented on GitHub (Oct 26, 2021):

Hi Stef,

I have the WireMock Version running on MAC Big Sur

Project 'MockingFW.C' has the following package references
   [net5.0]: 
   Top-level Package                 Requested         Resolved       
   > WireMock.Net                    1.4.24-ci-15542   1.4.24-ci-15542
   > WireMock.Net.OpenApiParser      1.4.24-ci-15542   1.4.24-ci-15542
   > WireMock.Net.StandAlone         1.4.24-ci-15542   1.4.24-ci-15542

This is my Canned Data

 {
    "TimeSettings": {
      "Start": "2021-10-26T12:00:00",
      "End": "2021-10-27T14:55:01"
    },
    "Request": {
      "Path": {
        "Matchers": [
          {
            "Name": "WildcardMatcher",
            "Pattern": "/cache",
            "IgnoreCase": false
          }
        ]
      },
      "Methods": [
        "DELETE",
        "POST",
        "PUT"
      ]
    },
    "Response": {
      "StatusCode": 200,
      "Body": "{{JsonPath.SelectToken request.body \"*\"}}",
      "UseTransformer": true,
      "BodyAsFileIsCached": true,
      "Headers": {
        "Content-Type": "application/json; charset=UTF-8",
        "Content-Length": "105",
        "Date": "Tue, 26 Oct 2021 15:41:14 GMT"
      }
    }
  }

How I check if this feature Works? This is my response regarding cache.

image

Thanks a Lot

@AndresGMD commented on GitHub (Oct 26, 2021): Hi Stef, I have the WireMock Version running on MAC Big Sur ``` Project 'MockingFW.C' has the following package references [net5.0]: Top-level Package Requested Resolved > WireMock.Net 1.4.24-ci-15542 1.4.24-ci-15542 > WireMock.Net.OpenApiParser 1.4.24-ci-15542 1.4.24-ci-15542 > WireMock.Net.StandAlone 1.4.24-ci-15542 1.4.24-ci-15542 ``` This is my Canned Data ``` { "TimeSettings": { "Start": "2021-10-26T12:00:00", "End": "2021-10-27T14:55:01" }, "Request": { "Path": { "Matchers": [ { "Name": "WildcardMatcher", "Pattern": "/cache", "IgnoreCase": false } ] }, "Methods": [ "DELETE", "POST", "PUT" ] }, "Response": { "StatusCode": 200, "Body": "{{JsonPath.SelectToken request.body \"*\"}}", "UseTransformer": true, "BodyAsFileIsCached": true, "Headers": { "Content-Type": "application/json; charset=UTF-8", "Content-Length": "105", "Date": "Tue, 26 Oct 2021 15:41:14 GMT" } } } ``` How I check if this feature Works? This is my response regarding cache. <img width="1023" alt="image" src="https://user-images.githubusercontent.com/90065355/138991689-181f90df-68e0-40f6-b371-b542e0dd50fa.png"> Thanks a Lot
Author
Owner

@StefH commented on GitHub (Oct 27, 2021):

For testing this specific functionality, you need that exact version:
image

(Note that only this version has your requested logic)

If that does not work work you, I'll merge the PR and create a new official NuGet.

@StefH commented on GitHub (Oct 27, 2021): For testing this specific functionality, you need that exact version: ![image](https://user-images.githubusercontent.com/249938/139010492-af0d4675-683f-49ce-a5f4-83702ef22bbc.png) (Note that only this version has your requested logic) If that does not work work you, I'll merge the PR and create a new official NuGet.
Author
Owner

@AndresGMD commented on GitHub (Oct 27, 2021):

Thanks Stef,

I've just available these versions:

image

I would appreciate if you merge in a new version. Thanks in advance

@AndresGMD commented on GitHub (Oct 27, 2021): Thanks Stef, I've just available these versions: <img width="416" alt="image" src="https://user-images.githubusercontent.com/90065355/139077782-11640ae5-7d46-4d80-9af8-c4cfbb9625aa.png"> I would appreciate if you merge in a new version. Thanks in advance
Author
Owner

@StefH commented on GitHub (Oct 27, 2021):

Official NuGet 1.4.25 will be available in a few minutes.

@StefH commented on GitHub (Oct 27, 2021): Official NuGet 1.4.25 will be available in a few minutes.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net-wiremock#368