GithubHelp home page GithubHelp logo

kong / apiembed Goto Github PK

View Code? Open in Web Editor NEW
407.0 30.0 52.0 1.69 MB

Embeddable API code snippets for your website, blog or API documentation

Home Page: https://apiembed.com

License: MIT License

JavaScript 32.24% Procfile 0.07% Pug 67.70%

apiembed's Introduction

APIembed - API Code snippets

Auto-generated, code snippets in many programming languages for your website, blog or API docs.

The target transformation is powered by HTTP Snippet. For any errors with the target syntax, or for additional target requests, please submit an issue there.

Main Targets:

  • Shell
  • Javascript
  • Node
  • C
  • Java
  • PHP
  • Objective-C
  • Swift
  • Python
  • Ruby
  • C#
  • Go
  • OCaml
  • You can add more languages here

We ♥ Open Source

The APIembed website and the APIembed API are open source. We'd love to hear your feedback!


Handcrafted by Kong

apiembed's People

Contributors

hutchic avatar nijikokun avatar sonicaghi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

apiembed's Issues

C# Code Snippet needs a clear handlers to work.

Our API requires that customers send vnd mime types in both the Accept and Content-Type headers.

With the C# example, the following code is provided:

var client = new RestClient("https://api.whispir.com/messages?apikey=REPLACE_ME");
var request = new RestRequest(Method.POST);
request.AddHeader("content-type", "application/vnd.whispir.message-v1+json");
request.AddHeader("accept", "application/vnd.whispir.message-v1+json");
request.AddHeader("authorization", "<REPLACE_ME>");
request.AddParameter("application/vnd.whispir.message-v1+json", "{\"to\":\"<REPLACE_ME>\",\"subject\":\"<REPLACE_ME>\",\"body\":\"<REPLACE_ME>\"}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);

The problem though is that the request.AddHeader method is not respected unless the following code is provided on line 2:

client.ClearHandlers();

This code clears the default handlers allowing the user to set custom headers.

Can you please include this in your out of the box rendering of C# code.

Could not load JSON source, please review the documentation and try again

Hello, please i need your help, I'm using
<iframe src="//api.apiembed.com/?source=http://localhost/test/demo.json&targets=all" frameborder="0" scrolling="no" width="100%" height="300px" seamless></iframe>

but it gives me this error
Could not load JSON source, please review the documentation and try again

my jsonfile is saved locally, I am stilling in localhost, and it's as follows:
`{
"method": "POST",
"url": "http://localhost/test/web/app_dev.php/v1/photos",
"httpVersion": "HTTP/1.1",
"queryString": [
{ "image": "photos/1.jpg", "value": "photos/1.jpg" }
],
"headers": [
{ "name": "Accept", "value": "application/json" },
{ "name": "Content-Type", "value": "application/json" }
],

"postData": {
"mimeType": "application/json",
"image": "{"photos/1.jpg": "photos/1.jpg"}"
}
}
`

Embedding the documentation in JS

Without requiring to link a doc from a third-party location.

Something like:

<div id="frame-container"></div>
<script type="text/javascript">
  var doc = {
    // Endpoint Documentation
  };
  render_iframe(doc, 'frame-container');
</script>

[golang example] Use http.DefaultClient instead of your own client

package main

import (
    "fmt"
    "strings"
    "net/http"
    "io/ioutil"
)

func main() {

    url := "http://mockbin.com/request?foo=bar&foo=baz"

    payload := strings.NewReader("{\"foo\": \"bar\"}")

    req, _ := http.NewRequest("POST", url, payload)

    req.Header.Add("cookie", "foo=bar; bar=baz")
    req.Header.Add("accept", "application/json")
    req.Header.Add("content-type", "application/json")

    res, _ := http.DefaultClient.Do(req)

    defer res.Body.Close()
    body, _ := ioutil.ReadAll(res.Body)

    fmt.Println(res)
    fmt.Println(string(body))

}

Support Data Urls or another way to embed the HAR directly

The current method for passing HAR data to the apiembed server is clunky and/or hard to use in cases where the HAR information is available at page load, or is generated at runtime, or when debugging an integration from a local development environment (which is not visible to external servers).

Some way of embedding the HAR data directly in the request would be extremely helpful in these situations. Data urls (which currently don't work) seem like an obvious choice, are completely backwards compatible, and require no additional parameters or interface changes.

The support for data urls could be done either at the unirest level, or by checking the source parameter before sending it to unirest, and decoding it directly if it is a data url.

Alternately an "har" parameter or similar which accepts the har data directly, and is mutually exclusive with the source parameter, would work.

I can submit a pull request with the necessary changes if there is any interest in either form of this functionality.

Dynamic height resizing

Some snippets are shorter than others so it would be cool to dynamically update the height.

Selecting targets UI

Instead of having an all checkbox it might be wise to have a "select all" / "unselect all" action and by default have them all selected.

The problem with it currently is that none are selected when loading the page even though they all show up in the preview and if you select all it disables the other checkboxes, causing a lot of clicks to get rid of httpie and wget.

Current:
screen shot 2015-03-11 at 4 31 24 pm

Proposed:
screen shot 2015-03-11 at 4 37 33 pm

"Loading" spinner

Sometimes it takes a while to load the widget. It would be nice to show a spinner instead of blank space.

apiembed.com down

It looks like the hosted website is down. Is this a temporary situation or should we be looking at alternatives?

Pure C#

C# without RestClient

var request = WebRequest.CreateHttp("https://api.whispir.com/messages?apikey=<REPLACE_ME>");
request.Method = "POST";
request.ContentType = "application/vnd.whispir.message-v1+json";
request.Accept = "application/vnd.whispir.message-v1+json";
request.Headers.Add("authorization", "<REPLACE_ME>");

var bytes = Encoding.UTF8.GetBytes("{\"to\":\"<REPLACE_ME>\",\"subject\":\"<REPLACE_ME>\",\"body\":\"<REPLACE_ME>\"}");

request.ContentLength = bytes.Length;

using (var stream = request.GetRequestStream()) {
	stream.Write(bytes, 0, bytes.Length);
	try {
		using (var response = request.GetResponse()) {
			var result = (new StreamReader(response.GetResponseStream())).ReadToEnd();
		}
	}
	catch (WebException wex) {
		using (var response = wex.Response) {
			var error = (new StreamReader(response.GetResponseStream())).ReadToEnd();
		}
	}
}

Tested a few API both failed, invalid JSON source / [object Object]

Hello, looks like a really cool service!

Things I noticed are both of the below are compress and also json-escape for URLs.

I had trouble with the below API which is from the json REST API being built into WordPress.
https://loqu.st/wp-json/
invalid JSON source, please review the documentation and try again

Also this API from contentDM
https://server16622.contentdm.oclc.org/dmwebservices/index.php?q=dmGetCollectionList/json

The message I get is :
[object Object],[object Object], please review the documentation and try again

Default target option when using targets=all

When using a comma separated list of all the desired targets (e.g., targets=php:curl,php:http1,php:http2,javascript:jquery,javascript:xhr,shell:curl,shell:wget,shell:httpie), some browser extensions, such as the Netcraft Extension for Google Chrome, will report the iFrame as a suspected XSS attack:

2015-04-15_18-01-16

If we change the source URL to use targets=all, the Netcraft Extension doesn't complain, however we then have no way of specifying a default target, so we end up with the default of C, which for our particular use-case doesn't make sense (we'd like to use php:curl as the default):

2015-04-15_18-21-45

If there was another option, e.g., default-target, that could be used in conjunction with targets=all, then we could specify targets=all&default-target=php:curl, so that PHP would be the default option selected in the widget.

Enhancing the PHP code templates

Hello,

very nice tool!

My suggestion:

In case of

...
"postData": {
    "mimeType": "application/x-www-form-urlencoded",
    "params" : [           
        {
            "name": "params[IDENTIFIER]",
            "value": "DUMMY_ACCOUNT"
        },
        {
            "name": "params[OPERATIONTYPE]",
            "value": "create"
        },
}
...

it would be nice that in the php code to have something like

...
CURLOPT_POSTFIELDS => http_build_query([
    'params[IDENTIFIER]' => 'DUMMY_ACCOUNT',
    'params[OPERATIONTYPE]' => 'create',
])
...

instead of

...
CURLOPT_POSTFIELDS => "params%5BIDENTIFIER%5D=DUMMY_ACCOUNT&params%5BOPERATIONTYPE%5D=create"
...

Literals in JSON text body are invalid

For some reason, this is okay (notice the prefer_sms field):

{"cookies": [], "postData": {"mimeType": "application/json", "text": "{\"foo\": \"bar\", \"name\": \"Will Gates\", \"prefer_sms\": \"false\"}"}, "url": "http://mockbin.com/request", "queryString": [], "headers": [{"name": "Accept", "value": "application/json"}, {"name": "Content-Type", "value": "application/json"}], "method": "POST", "httpVersion": "HTTP/1.1"}

But this isn't:

{"cookies": [], "postData": {"mimeType": "application/json", "text": "{\"foo\": \"bar\", \"name\": \"Will Gates\", \"prefer_sms\": false}"}, "url": "http://mockbin.com/request", "queryString": [], "headers": [{"name": "Accept", "value": "application/json"}, {"name": "Content-Type", "value": "application/json"}], "method": "POST", "httpVersion": "HTTP/1.1"}

Even though both are valid JSON. Not sure what to do about this.

Angular 2+ Support?

Hello, I want to ask, is there anyway you will create angular 2+ support? Or anyway I could contribute? Thanks

Mod_security blocks as no User Agent is specified in the request

I am using a PHP script to generate the HAR object based on request parameters. This allows me to pass a source URL to APIEmbed, and generate different outputs based on what the user requires.

What i have noticed since pushing this script into production is that the APIEmbed function doesn't work when attempting to run the PHP script hosted on apache running mod-security.

The key violation is that there is no User Agent specified in the request.

[Thu Nov 05 10:04:49.863381 2015] [:error] [pid xxxxx] [client xxxxxx] 
ModSecurity: Access denied with code 403 (phase 2). Operator EQ matched 0 at REQUEST_HEADERS. [file 
"/etc/httpd/modsecurity.d/activated_rules/modsecurity_crs_21_protocol_anomalies.conf"] 
[line "66"] [id "960009"] [rev "1"] 
[msg "Request Missing a User Agent Header"] 
[severity "NOTICE"] 
[ver OWASP_CRS/2.2.6"] 
[maturity "9"] 
[accuracy "9"] 
[tag "OWASP_CRS/PROTOCOL_VIOLATION/MISSING_HEADER_UA"] 
[tag "WASCTC/WASC-21"] 
[tag "OWASP_TOP_10/A7"] 
[tag "PCI/6.5.10"] 
[hostname "xxxxxxxxx"]
[uri "xxxxxxxxxxx/generateSampleCode.php"] 
[unique_id "xxxxxxxxxx"]

This means that I need to modify my security to allow this through. The better function would be for the APIEmbed solution to specify a User-Agent when requesting the JSON source.

Http basic auth

Is prompting for http basic auth possible? How would that work?

Headers in Node Http not working

Config Example:

{
    "method": "POST",
    "url": "https://api.z-api.io/instances/SUA_INSTANCIA/token/SEU_TOKEN/send-text",
    "httpVersion": "HTTP/1.1",
    "queryString": [],
    "headers": [
        {
            "name": "Content-Type",
            "value": "application/json"
        }
    ],
    etc..... 

Result:

var http = require("https");

var options = {
 "method": "POST",
 "hostname": "example.com",
 "port": null,
 "path": "/save",
 "headers": {} // headers empty
};

Invalid snippet on homepage

curl --request POST \
  --url "http://httpconsole.com/debug?foo=bar&foo=baz" \
  --cookie "foo=bar; bar=baz" \
  --header "Accept: text/plain" \
  --header "Content-Type: application/json" \
  --data "{\"foo\": \"bar\"}"

Gives:

Cannot POST /debug?foo=bar&amp;foo=baz

Add options to widget as an option

A lot of the snippets have various options, would be nice to somehow allow them to be configurable from within the widget or during widget creation.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.