You can find all available mock methods here. If you want to mock this module in your tests, you can replace the underlying lets-fetch library with the provided mock module, e.g. error ( 'Things went badly', err ) ) Mocking items = ( ) => new ItemsEndpoint ( api ) // Use the new, overwritten endpoint api. post = function ( ) // Attach it to the client, either as a new endpoint or overwriting an already existing one api. memory) should be at the start of the list.Ĭonst client = require ( 'gw2api-client' ) const AbstractEndpoint = require ( 'gw2api-client/src/endpoint' ) // Get an instance of an API client const api = client ( ) // Example: Add a new function inside the abstract endpoint AbstractEndpoint. The more persistent and more reliable cache storages should therefore be on the end of the list and the fastest (e.g. In this case, the cache gets saved in all storages and read from the first storage in the list answering with a valid value. You can also chain multiple cache storages together. Therefore it can happen that some data gets requested twice, if you request it in rapid succession and are not using a cache that saves in memory (memory or browser caches). During this time, the API function already resolves a result for best performance. Note: The cache storage save is asynchronous in the background. ids ( ) // You can skip the cache for guaranteed live data api. ids ( ) // When the cache expires, this will call the official API again api. cacheStorage ( cacheMemory ( ) ) // This will only call the official API once api. You can find the default cache times of all endpoints here.Ĭonst cacheMemory = require ( 'gw2api-client/src/cache/memory' ) api. However, you can easily enable caching for all appropriate endpoints by giving the client a cache storage to work with. You can find all cache storages (and the interface for custom ones) in this document.īy default, calling any endpoint requests data from the live API. You can find all endpoints and their respective function calls in this document. log ( item ) ) // Get multiple items api. who run the Old Town as their personal domain, keeping the cops and the. log ( items ) ) // Get a single item api. If you sat with Miller's books on your lap, you could follow the action almost. authenticate ( 'my-secret-key' ) // Get the ids of all items api. language ( 'en' ) // Optional: Authenticate the client using an API key api. schema ( '' ) // Optional: Set the language of the client api. Const client = require ( 'gw2api-client' ) // Get an instance of an API client let api = client ( ) // Optional, but recommended: Set the schema version of the client api.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |