
Product
Rust Support Now in Beta
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
@speakeasy-api/react-embeds
Advanced tools

Embed Speakeasy's React components in your API developer portal to augment your static API documentation with a magical developer experience. With our components, onboarding to and ongoing usage of your API becomes self-service for your users.
All the components we offer are composable, meaning you can use them in isolation, or any combination. Our available components are:
npm install @speakeasy-api/react-embeds
#or
yarn add @speakeasy-api/react-embeds
To embed Speakeasy components in your application, the first step is making sure they are properly authenticated and filtered for the logged in customer. After which you will be able to easily add the component into your react app
To get Speakeasy components working correctly, you will need to generate an accessToken
filtered to the correct subset of data. There are two ways to generate an accessToken
:
/v1/workspace/embed-access-token
endpoint are read-only
.Creating a filtered accessToken
in the SDK is a language-specific activity. For the full range of supported languages, see our documentation. This instruction set will be in Go.
Add the sdk to your api project according to the documentation.
// routes.go
func addPublicRoutes(r *mux.Router) {
r := mux.NewRouter()
speakeasySDK := speakeasy.New(speakeasy.Config {
APIKey: "YOUR API KEY HERE",
ApiID: "main_api",
VersionID: "1.0.0",
}
r.Use(speakeasySDK.Middleware)
// Your paths
}
Embed tokens can provide access to only a subset of your data, if desired. This is useful for allowing each of your customers to use your embedded component to view only their own data or for restricting which apis, versions, or endpoints you'd like to expose in your embedded component.
// controller.go
func EmbedAuthHandler(w http.ResponseWriter, r *http.Request) {
ctrl := speakeasy.MiddlewareController(req)
// Use your existing authentication provider or logic for the embed access token.
customerID := auth.GetCustomerID(req)
accessToken, err := ctrl.GetSDKInstance().GetEmbedAccessToken(ctx, &embedaccesstoken.EmbedAccessTokenRequest{
Filters: []*embedaccesstoken.EmbedAccessTokenRequest_Filter{
{
Key: "customer_id",
Operator: "=",
Value: customerID,
},
},
})
w.WriteHeader(http.StatusOK)
if err := json.NewEncoder(w).Encode(EmbedResponse{AccessToken: accessToken}); err != nil {
// handle error
}
}
// models.go
type EmbedResponse struct {
AccessToken string `json:"access_token"`
}
// routes.go
func addPublicRoutes(r *mux.Router) {
r := mux.NewRouter()
speakeasySDK := speakeasy.New(speakeasy.Config {
APIKey: "YOUR API KEY HERE",
ApiID: "main_api",
VersionID: "1.0.0",
}
r.Use(speakeasySDK.Middleware)
r.Path("v1/auth/embed-token").Methods(http.MethodGet).HandlerFunc(EmbedAuthHandler)
// Your other paths
}
export const DataView = () => {
const [embedToken, setEmbedToken] = useState(undefined);
// This function will call the handler that you defined in step two.
const getEmbedToken = useCallback(async () => {
const accessTokenResponse = await axios.get("https://my-api.dev/v1/auth/embed-token);
return accessTokenResponse.data.access_token;
}, []);
// Set the initial token
useEffect(() => {
getEmbedToken.then(token => setEmbedToken(token));
}, [])
return (
<div>
<h1>View your data</h1>
<SpeakeasyRequestsComponent
accessToken={embedToken}
onRefetchAccessToken={getEmbedToken}
/>
</div>
)
}
Set the accessToken
in your react code by configuring a SpeakeasyFilter object:
type SpeakeasyFilter = {
// Currently supported filter keys.
key: 'customer_id' | 'created_at';
operator: '=' | '<' | '>';
value: string;
}
customer_id
should almost always be set in your filter to restrict data to a single customer, lest you unintentionally share another customer's data.
The filters you configure are then serialized as json into the filters
query parameter in the API request you will make.
const filters = useMemo(() => {
const customerId = ""; // your customer id.
return {
filters: [{
key: "customer_id",
operator: "=",
value: customerId
}]
};
}), [];
return (await axios.get("https://app.speakeasyapi.dev/v1/workspace/embed-access-token", {
headers: {
"x-api-key": "" // your api key
},
params: {
filters
}
})).data.access_token;
}, []);
accessToken
refreshNest the GET request from step 2 in onRefetchAccessToken
a callback function that triggers when the 'accessToken' expires
const onRefetchAccessToken = useCallback(async () => {
return (await axios.get("https://app.speakeasyapi.dev/v1/workspace/embed-access-token", {
headers: {
"x-api-key": "" // your api key
},
params: {
filters
}
})).data.access_token;
}, []);
useEffect(() => {
getAccessToken()
.then(access_token => setAccessToken(access_token))
}, []);
Put it all together for a full example of constructing a filters object and making an API request:
const App () => {
const [accessToken, setAccessToken] = useState("");
const filters = useMemo(() => {
const customerId = ""; // your customer id.
return {
filters: [{
key: "customer_id",
operator: "=",
value: customerId
}]
};
}), [];
const onRefetchAccessToken = useCallback(async () => {
return (await axios.get("https://app.speakeasyapi.dev/v1/workspace/embed-access-token", {
headers: {
"x-api-key": "" // your api key
},
params: {
filters
}
})).data.access_token;
}, []);
useEffect(() => {
getAccessToken()
.then(access_token => setAccessToken(access_token))
}, []);
// return
}
After a filtered accessToken
has been created, adding the react components to your app should be easy. Speakeasy components can be added directly into your react pages. The authentication props are passed directly into the embedded component. See the example below:
const SomeReactComponent = (props) => {
// logic
return (
<>
<YourComponent />
<SpeakeasyRequestsComponent
accessToken={myApiToken}
onRefetchAccessToken={myApiTokenRefreshFunc}
/>
</>
<YourOtherComponent />
)
If you have multiple components that are using the same access token, a SpeakeasyConfigure
component can simplify the integration
const App = () => {
// authentication
return (
<>
<SpeakeasyConfigure
accessToken={myApiToken}
onRefetchAccessToken={amyApiTokenRefresh}
>
<SpeakeasyApiComponent />
<SpeakeasyRequestsComponent />
</SpeakeasyConfigure>
<>
);
}
FAQs

The npm package @speakeasy-api/react-embeds receives a total of 0 weekly downloads. As such, @speakeasy-api/react-embeds popularity was classified as not popular.
We found that @speakeasy-api/react-embeds demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 7 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.