How to use httpsnippet - 7 common examples

To help you get started, we’ve selected a few httpsnippet examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Kong / insomnia / packages / insomnia-app / app / ui / components / modals / generate-code-modal.js View on Github external
async _generateCode(request, target, client) {
    // Some clients need a content-length for the request to succeed
    const addContentLength = (TO_ADD_CONTENT_LENGTH[target.key] || []).find(c => c === client.key);

    const { environmentId } = this.props;
    const har = await exportHarRequest(request._id, environmentId, addContentLength);
    const snippet = new HTTPSnippet(har);
    const cmd = snippet.convert(target.key, client.key);

    this.setState({ request, cmd, client, target });

    // Save client/target for next time
    window.localStorage.setItem('insomnia::generateCode::client', JSON.stringify(client));
    window.localStorage.setItem('insomnia::generateCode::target', JSON.stringify(target));
  }
github Kong / insomnia / packages / insomnia-app / app / ui / components / modals / generate-code-modal.js View on Github external
render() {
    const { cmd, target, client } = this.state;
    const { editorFontSize, editorIndentSize, editorKeyMap } = this.props;

    const targets = availableTargets();

    // NOTE: Just some extra precautions in case the target is messed up
    let clients = [];
    if (target && Array.isArray(target.clients)) {
      clients = target.clients;
    }

    return (
      
        Generate Client Code
github ErikWittern / openapi-snippet / index.js View on Github external
const formatTarget = function (targetStr) {
  const language = targetStr.split('_')[0]
  const title = capitalizeFirstLetter(language)
  const library = targetStr.split('_')[1]

  const validTargets = HTTPSnippet.availableTargets()
  let validLanguage = false
  let validLibrary = false
  for (let i in validTargets) {
    const target = validTargets[i]
    if (language === target.key) {
      validLanguage = true
      if (typeof library === 'undefined') {
        library = target.default
        validLibrary = true
      } else {
        for (let j in target.clients) {
          const client = target.clients[j]
          if (library === client.key) {
            validLibrary = true
            break
          }
github Kong / insomnia / packages / insomnia-app / app / ui / containers / app.js View on Github external
async _handleCopyAsCurl(request) {
    const { activeEnvironment } = this.props;
    const environmentId = activeEnvironment ? activeEnvironment._id : 'n/a';
    const har = await exportHarRequest(request._id, environmentId);
    const snippet = new HTTPSnippet(har);
    const cmd = snippet.convert('shell', 'curl');
    clipboard.writeText(cmd);
  }
github brookshi / Hitchhiker / client / src / components / code_snippet_dialog / index.tsx View on Github external
private refresh(record: DtoRecord, language: CodeSnippetLang, type: string) {
        const har = new HAR(record);
        let code = '';
        try {
            const snippet = new HTTPSnippet(har);
            code = snippet.convert(language, type);
        } catch (ex) {
            code = JSON.stringify(ex);
        }
        this.setState({ ...this.state, language, type, code });
    }
github sumory / moklr / routes / mock.js View on Github external
var express = require('express');
var router = express.Router();
var HTTPSnippet = require('httpsnippet');
var util = require("util");
var logger = require('../lib/log.js').logger('mock');

var availableTargets = HTTPSnippet.availableTargets().reduce(function (targets, target) {
    if (target.clients) {
        targets[target.key] = target.clients.reduce(function (clients, client) {
            clients[client.key] = false;
            return clients
        }, {})
    } else {
        targets[target.key] = false;
    }

    return targets
}, {});

router.get('/create', function (req, res, next) {
    res.render('create');
});
github Kong / insomnia / packages / insomnia-app / app / ui / components / modals / generate-code-modal.js View on Github external
import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import autobind from 'autobind-decorator';
import HTTPSnippet, { availableTargets } from 'httpsnippet';
import CopyButton from '../base/copy-button';
import { Dropdown, DropdownButton, DropdownItem } from '../base/dropdown';
import CodeEditor from '../codemirror/code-editor';
import Modal from '../base/modal';
import ModalBody from '../base/modal-body';
import ModalHeader from '../base/modal-header';
import ModalFooter from '../base/modal-footer';
import { exportHarRequest } from '../../../common/har';
import Link from '../base/link';

const DEFAULT_TARGET = availableTargets().find(t => t.key === 'shell');
const DEFAULT_CLIENT = DEFAULT_TARGET.clients.find(t => t.key === 'curl');
const MODE_MAP = {
  c: 'clike',
  java: 'clike',
  csharp: 'clike',
  node: 'javascript',
  objc: 'clike',
  ocaml: 'mllike',
};

const TO_ADD_CONTENT_LENGTH = {
  node: ['native'],
};

@autobind
class GenerateCodeModal extends PureComponent {

httpsnippet

HTTP Request snippet generator for *most* languages

Apache-2.0
Latest version published 1 year ago

Package Health Score

70 / 100
Full package analysis

Popular httpsnippet functions