HTTP API - Basic

Number of APIs: 3

🚀 Let's do this!

This collection will help you understand how to use the Momento HTTP API to get, set, update, and delete values in a cache using a basic string as a cache key. If you prefer to use base64 encoded values as your cache keys, check out the [HTTP API - Advanced collection]

🧠 Know before you go

We're dealing with cache items and cache keys. There are a couple of things you need to know before using the API.

Data expiration

Cache items expire automatically! That's one of the main reasons to use a cache - to store short-lived data. In Momento you're required to provide a time to live (TTL) on every cache set so the service knows how long to keep your data around. Once your TTL has elapsed, we'll delete it for you, no need to clean up yourself!

Key names

There are a couple of variables configured in this collection that let it run hands-free. Let's talk about them real quick.

  • cacheName - This is the name of a cache that exists in your Momento account, specifically in the region for which your API key was created. If you get a 404 saying Cache not found, check this variable and make sure it aligns with a cache you created in your account.
  • cacheKey - This is the name of a cache item we'll be manipulating. Wanna know something cool? It can be whatever you want! This is a string value that is entirely up to you to decide naming convention. We recommend something meaningful though, so you know where to find it later!

🔖 How to use this collection

Step 1: Send requests

This API allows you to perform CRUD operations using the GET, PUT, and DELETE HTTP methods.

This collection contains each of these [request] types. Open each request and click Send to see what happens. Or, click on the Run icon in the upper right to see them all run in sequence!

Step 2: View responses

Observe the response tab for status code (200 OK), response time, and size.

Step 3: Send new Body data for CREATE and UPDATE requests

Update or add new data in Body in the PUT request. This is plaintext - so you can add anything you want and it will be saved in the cache as-is.

Hello world!

Step 4: Update the MOMENTOAUTH and BASEURL variables

Variables enable you to store and reuse values in Qodex. In the Momento HTTP API environment, we have two variables named MOMENTO_AUTH and BASE_URL.

  • MOMENTO_AUTH - An API key from your Momento account used for authentication. You can [follow the steps here] to obtain your API key.
  • BASE_URL - Represents the endpoint specific to the region your API key was created for. Whenever you run any request in this collection, the value in the MOMENTO_AUTH environment variable is required for proper authentication.

If you haven't set your API token in the environment variable, it's not too late! Visit the Momento console, create a new API key, come back here, and save it into the empty MOMENTO_AUTH variable contained in the [Momento HTTP API environment]

Be sure to also update the BASE_URL environment variable with the value from the HTTP Endpoint field when generating your key!!

Step 5: Add tests in the Tests tab

Our requests have tests written in JavaScript to make sure they are running as expected. After a response is received, our tests assert certain values exist, status codes are returned, and performance times are up to snuff. You can view our test scripts and make any changes you'd like in the Tests tab. You can view the results of the tests in the Test Results tab.

Step 6: Learn more

If you want to learn more about the API, you can [check out the spec] or view our dev docs, the choice is yours!

  1. Update item with JSON PUT {{BASE_URL}}/cache/:cacheName?key={{cacheKey}}&ttl_seconds={{timeToLiveSeconds}}

  2. Check updated item - CACHE HIT GET {{BASE_URL}}/cache/:cacheName?key={{cacheKey}}

  3. Delete item DELETE {{BASE_URL}}/cache/:cacheName?key={{cacheKey}}