Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-apiembed

Package Overview
Dependencies
Maintainers
2
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-apiembed

React api embed component.

  • 0.1.8
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
349
decreased by-37.79%
Maintainers
2
Weekly downloads
 
Created
Source

react-apiembed

version

React components encapsulating functionality of apiembed. Allows you to generate code snippets from HARs, all in the browser, with the power of react. Examples

Built with:

React components included

  • <CodeSnippet .../> - Render a code snippet from a HAR.
  • <CodeSnippetWidget .../> - Tabbed UI for selecting languages to render individual CodeSnippets
  • <Apiembed .../> - WIP

Setup

yarn install
# or
npm install

Usage

Using as a ES module:

import React from "react"
import { render } from "react-dom"
import { CodeSnippet, CodeSnippetWidget } from "react-apiembed"

class MyApp extends React.Component {
  render() {
    const har = {
      method: "POST",
      url: "http://mockbin.com/request",
      httpVersion: "HTTP/1.1",
      queryString: [{ name: "foo", value: "bar" }, { name: "foo", value: "baz" }],
      headers: [
        { name: "Accept", value: "application/json" },
        { name: "Content-Type", value: "application/json" }
      ],
      cookies: [{ name: "foo", value: "bar" }, { name: "bar", value: "baz" }],
      postData: { mimeType: "application/json", text: '{"foo": "bar"}' }
    }

    return (
      <div>
        <CodeSnippet har={har} prismLanguage="javascript" target="javascript" client="jquery" />
        <CodeSnippetWidget
          har={har}
          snippets={[
            {
              prismLanguage: "go",
              target: "go"
            },
            {
              prismLanguage: "bash",
              target: "shell",
              client: "curl"
            }
          ]}
        />
      </div>
    )
  }
}

render(<MyApp />, document.getElementById("root"))

Props

<CodeSnippet/>

NameRequiredDefaultTypeDescription
harObjectHAR Request object as outlined here
prismLanguageStringPrism languages. Currently supports: bash, javascript, php, go, ruby, ocaml, ruby, java, python, swift, csharp, clike
targetStringhttpsnippet target prop e.g. "node", "javascript", "shell", "go" etc.
clientnullStringhttpsnippet client prop. e.g. "xhr", "curl" etc.

<CodeSnippetWidget/>

NameRequiredTypeDescription
harObjectHAR Request object as outlined here
snippetsObjectArray of snippet objects

snippet properties

NameRequiredDefaultTypeDescription
prismLanguageStringPrism languages. See above for supported languages.
targetStringhttpsnippet target prop e.g. "node", "javascript", "shell", "go" etc.
clientnullStringhttpsnippet client prop. e.g. "xhr", "curl" etc.

Testing

npm run test

FAQs

Package last updated on 26 Aug 2022

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc