Topics - Event Notifications

Number of APIs: 2

You made it!

You're probably here because you heard about how cool Momento Topics are and wanted to try it for yourself, right? I knew it!

Welcome to the collection! This is going to be short and sweet because, well, there's only a couple of things for you to do here: publish to a topic of your choice and subscribe for messages on that topic. So let's get started!

Getting started

If you haven't walked through the getting started section of our [HTTP API - Basics] collection, I highly recommend you do so. Still around? Ok, let's go through it.

  1. Go create an API key from the Momento Console. It's free, don't worry.

  2. You're also going to want to make a cache while you're in there. Just hit that 'Create Cache' button in the upper right corner and give it a name.

  3. Bring that token back here and fork this collection into your workspace. You might want to fork the [Momento HTTP API environment] while you're at it too.

  4. In your fork, paste the token from the Momento Console in the MOMENTO_AUTH environment variable.

  5. Now go to the Variables tab of this collection in your fork. You'll want to put the name of the cache you created in step 2 in the cacheName variable.

  6. You can also enter a value in the topicName variable. This will be the unique channel you're publishing or subscribing to.

  7. Open up the Publish request in this collection and view the documentation to go on from here.

What even is this?

If you're wondering what Topics are and why you need it in your life, great question! Topics is a low-latency serverless event messaging service from Momento that acts very closely to a managed WebSocket service. Instead of using the wss protocol and forcing you to manage connections yourself, Momento will create a long polling connection (aka connection waits for something to happen and doesn't timeout) with a topic when you subscribe and manage all the connectivity on your behalf.

What we're doing in this collection is both publishing and subscribing to a topic. No tricky connections to manage here, we're just sending and receiving data from Momento that will be sent to all the subscribers. You know Slack? Yeah, just like how you send messages to a DM or channel in Slack. It uses connections like this to instantly send messages to everyone in a channel or DM. That said, Slack is not built on Momento Topics, but hopefully now you understand what it is you're using here.

Is there more information?

Of course there is! We write extensively about Topics and solutions on the Momento blog and have our API reference documented in the developer docs.

You can also have a glance at the [API reference in Qodex] if you'd prefer not to jump to an external site.

Happy coding!

  1. Publish POST {{BASE_URL}}/topics/:cacheName/:topicName

  2. Subscribe GET {{BASE_URL}}/topics/:cacheName/:topicName