From 485e00bbaa9a4bfbf4750d663e0dd329497afaac Mon Sep 17 00:00:00 2001 From: Dikran Samarjian Date: Wed, 11 Mar 2026 15:50:35 -0700 Subject: [PATCH] updated blocks example to devvit web for api client --- .../classes/RedditAPIClient.md | 36 ++++++++++--------- .../classes/RedditAPIClient.md | 36 ++++++++++--------- 2 files changed, 38 insertions(+), 34 deletions(-) diff --git a/docs/api/redditapi/RedditAPIClient/classes/RedditAPIClient.md b/docs/api/redditapi/RedditAPIClient/classes/RedditAPIClient.md index 54ef97a..0afb8fd 100644 --- a/docs/api/redditapi/RedditAPIClient/classes/RedditAPIClient.md +++ b/docs/api/redditapi/RedditAPIClient/classes/RedditAPIClient.md @@ -6,27 +6,29 @@ The Reddit API Client -To use the Reddit API Client, add it to the plugin configuration at the top of the file. +To use the Reddit API Client, enable the `redditAPI` permission in your `devvit.json` file. + +```json title="devvit.json" +{ + "permissions": { + "redditAPI": true + } +} +``` ## Example ```ts - -Devvit.configure({ - redditAPI: true, - // other plugins -}) - -// use within one of our capability handlers e.g. Menu Actions, Triggers, Scheduled Job Type, etc -async (event, context) => { - const subreddit = await context.reddit.getSubredditById(context.subredditId); - context.reddit.submitPost({ - subredditName: subreddit.name, - title: 'test post', - text: 'test body', - }) - // additional code -} +import { reddit } from '@devvit/web/server'; + +export const menuActionHandler = async () => { + const subredditName = await reddit.getCurrentSubredditName(); + return await reddit.submitPost({ + subredditName, + title: 'test post', + text: 'test body', + }); +}; ``` ## Constructors diff --git a/versioned_docs/version-0.12/api/redditapi/RedditAPIClient/classes/RedditAPIClient.md b/versioned_docs/version-0.12/api/redditapi/RedditAPIClient/classes/RedditAPIClient.md index ed4a879..d836beb 100644 --- a/versioned_docs/version-0.12/api/redditapi/RedditAPIClient/classes/RedditAPIClient.md +++ b/versioned_docs/version-0.12/api/redditapi/RedditAPIClient/classes/RedditAPIClient.md @@ -6,27 +6,29 @@ The Reddit API Client -To use the Reddit API Client, add it to the plugin configuration at the top of the file. +To use the Reddit API Client, enable the `redditAPI` permission in your `devvit.json` file. + +```json title="devvit.json" +{ + "permissions": { + "redditAPI": true + } +} +``` ## Example ```ts - -Devvit.configure({ - redditAPI: true, - // other plugins -}) - -// use within one of our capability handlers e.g. Menu Actions, Triggers, Scheduled Job Type, etc -async (event, context) => { - const subreddit = await context.reddit.getSubredditById(context.subredditId); - context.reddit.submitPost({ - subredditName: subreddit.name, - title: 'test post', - text: 'test body', - }) - // additional code -} +import { reddit } from '@devvit/web/server'; + +export const menuActionHandler = async () => { + const subredditName = await reddit.getCurrentSubredditName(); + return await reddit.submitPost({ + subredditName, + title: 'test post', + text: 'test body', + }); +}; ``` ## Constructors