All Projects → antoinechalifour → Memento

antoinechalifour / Memento

Licence: mit
Memento is a development-only tool that caches HTTP calls once they have been executed.

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Memento

Bigcache
Efficient cache for gigabytes of data written in Go.
Stars: ✭ 5,304 (+1295.79%)
Mutual labels:  hacktoberfest, cache, caching
Nuster
A high performance HTTP proxy cache server and RESTful NoSQL cache server based on HAProxy
Stars: ✭ 1,825 (+380.26%)
Mutual labels:  cache, caching, proxy
Haproxy
HAProxy Load Balancer's development branch (mirror of git.haproxy.org)
Stars: ✭ 2,463 (+548.16%)
Mutual labels:  cache, caching, proxy
Ola
The Open Lighting Architecture - The Travel Adaptor for the Lighting Industry
Stars: ✭ 424 (+11.58%)
Mutual labels:  api, cli, hacktoberfest
Pizzly
The simplest, fastest way to integrate your app with an OAuth API 😋
Stars: ✭ 796 (+109.47%)
Mutual labels:  api, hacktoberfest, proxy
Pypistats
Command-line interface to PyPI Stats API to get download stats for Python packages
Stars: ✭ 86 (-77.37%)
Mutual labels:  api, cli, hacktoberfest
Axios Module
Secure and easy axios integration with Nuxt.js
Stars: ✭ 998 (+162.63%)
Mutual labels:  api, hacktoberfest, proxy
Tutorialdb
A search 🔎 engine for programming/dev tutorials, See it in action 👉
Stars: ✭ 93 (-75.53%)
Mutual labels:  api, hacktoberfest, devtools
Fiddler Plus
自定义的Fiddler规则,多环境切换、解决跨域开发、快速调试线上代码必备|高效调试分析利器
Stars: ✭ 325 (-14.47%)
Mutual labels:  proxy, devtools
Cache
The Cache component provides an extended PSR-6 implementation for adding cache to your applications.
Stars: ✭ 3,606 (+848.95%)
Mutual labels:  cache, caching
Compoxure
Proxy middleware for express that enables composition of microservices.
Stars: ✭ 332 (-12.63%)
Mutual labels:  cache, proxy
Teachcode
A tool to develop and improve a student’s programming skills by introducing the earliest lessons of coding.
Stars: ✭ 325 (-14.47%)
Mutual labels:  cli, hacktoberfest
Graphback
Graphback - Out of the box GraphQL server and client
Stars: ✭ 323 (-15%)
Mutual labels:  cli, hacktoberfest
Ack3
ack is a grep-like search tool optimized for source code.
Stars: ✭ 330 (-13.16%)
Mutual labels:  cli, hacktoberfest
Horusec
Horusec is an open source tool that improves identification of vulnerabilities in your project with just one command.
Stars: ✭ 311 (-18.16%)
Mutual labels:  cli, hacktoberfest
Loopback Next
LoopBack makes it easy to build modern API applications that require complex integrations.
Stars: ✭ 3,972 (+945.26%)
Mutual labels:  api, hacktoberfest
Service Proxy
API gateway for REST and SOAP written in Java.
Stars: ✭ 355 (-6.58%)
Mutual labels:  api, proxy
Ghost Cli
CLI Tool for installing & updating Ghost
Stars: ✭ 313 (-17.63%)
Mutual labels:  cli, hacktoberfest
Askql
AskQL is a query language that can express any data request
Stars: ✭ 352 (-7.37%)
Mutual labels:  api, hacktoberfest
Cachier
Persistent, stale-free, local and cross-machine caching for Python functions.
Stars: ✭ 359 (-5.53%)
Mutual labels:  cache, caching

Build Status codecov

Memento

Memento is a development-only tool that caches HTTP calls once they have been executed

Memento screenshot

Why should one use Memento?

When building a UI or working on any project that rely on external services, some things can slow us down:

  • the API may not be stable at the moment
  • the API may apply harsh rate-limiting (and that's terrible if you forget the dependency array in your React.useEffect 😉)
  • ...or you may be working on a train or plane where the network is not reliable.

Memento has been built to solve these problems.

Memento acts as a development buddy that remembers the requests that your application is sending, the server response, and will respond to your app without the need for requests to go over the internet.

Pro-tip: Memento may also be used for stubbing external services for integration or end-to-end testing 🎉

Getting started

1. Add a Memento configuration file

To add Memento to your project, you need to add a .mementorc file to your project root.

Note: you may use any other configuration file supported by cosmiconfig.

The most basic configuration file to cache the PunkApi would look something like this:

{
  "targetUrl": "https://api.punkapi.com/v2"
}

2. Target the endpoint

You will then need to configure your app to target http://localhost:3344 as the API url.

Note: this should only be done at development time, do not target localhost for your production build!

3. Run Memento

You can then run Memento using npx @antoinechalifour/memento.

Note: npx is a command that comes with npm when installing Node and enables users to run binaries without installing them manually.

Options

The following options are supported:

Option Description Example Default value
targetUrl The API base URL http://localhost:4000 None
port The port used to launch Memento 9876 3344
cacheDirectory The cache directory used for storing responses memento-integration .memento-cache
useRealResponseTime Whether Memento should respond using the actual response time true false
disableCachingPatterns An array of patterns used to ignore caching certain requests [{ method: 'post', urlPattern: '/pokemon/*/sprites' }] []
ignoreCookiesPattern A regular expression for ignoring cookies AMP_TOKEN|_ga.*|_gid null

Option: disableCachingPatterns

You may use disableCachingPatterns in your configuration to tell Memento to ignore caching responses based on the request method and URL. As an example, if you wish to not cache routes likes /pokemon/mew/abilities and pokemon/ditto/abilities, you may use the following configuration :

{
  // ... your configuration
  "disableCachingPatterns": [{
    "method": "GET",
    "urlPattern": "/pokemon/*/abilities"
  }]
}

The minimatch package is used for comparing glob patterns and the actual url. You may use a tool like globtester to test your configurations.

Recipe: ignore caching all POST requests

{
  // ... your configuration
  "disableCachingPatterns": [{
    "method": "post",
    "urlPattern": "**"
  }]
}

Option: ignoreCookiesPattern

Even though Memento play well with stateless APIs, you may want to use it against APIs which use cookies. This might be tricky if the server always sets different cookies (thus cached requests cannot be replayed as the change every time they are made).

Memento provides an ignoreCookiesPattern which allows you to tell Memento not to care about cookies that match the regular expression that you provided.

Note: you may use Regexr to test your configuration.

Note: as Memento runs over HTTP, secure cookies will be downgraded to normal cookies.

Recipe: ignore Google Analytics cookies

A common use case is ignoring Google Analytics cookies : _ga, _gid, _gat, _gac-*, AMP_TOKEN. The following configuration tells Memento to ignore such cookies:

{
  // ... your configuration
  "ignoreCookiesPattern": "AMP_TOKEN|_ga.*|_gid"
}

Examples

Using the CLI

Launching Memento will start the interactive Memento CLI, where you can type commands to modify the cached requests and responses. The documentation can be found by typing help in the command prompt.

Command: import

You may import cURL commands into Memento. This feature is intended to be used as such:

  1. develop your app like the API is ready

  2. open the "network" tab in the Chrome devtools

  3. right click the failed request and select "copy as cURL"

    How to copy curl

  4. use the "import" command in memento and paste the cURL command.

    How to import curl

  5. you can now edit the response in your editor to stub the API call 🎉

Note: Memento will open the editor defined in your EDITOR environment variable. Non-terminal editors are not supported.

Cache location

By default, memento will create a .memento-cache directory in the current directory where each response will be mapped to a directory containing:

  • metadata.json - A file containing information about the request and the response.
  • body.{json,xml,txt} - The response content. The extension depends on the response content-type header. You may edit this file to edit the response.

You may override this directory by providing a cacheDirectory in the configuration file. this may be useful for storing environment dependent responses.

Contributing

Below is a list of commands you will probably find useful.

# Start TS compilation in watch mode
yarn start

# Start the local server
yarn dev
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].