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

apimaker

Package Overview
Dependencies
Maintainers
0
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apimaker

uri-string to api conversion tool

  • 0.0.1-0
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-75%
Maintainers
0
Weekly downloads
 
Created
Source

APIMAKER

the apimaker transforms uri-strings to cool APIs

docu is currently alpha i would say

please see the /sample folder for some examples

installation

  >npm install apimaker
  

then

  var apimaker = require("apimaker");
  

create a GET request api

  //var api = apimaker(uri, method, headers); 
  
  //a GET API 
  //GET is default
  var expand = apimaker("https://www.googleapis.com/urlshortener/v1/url?shortUrl=&key=&projection=");
  
  //use it
  //api(oneTimeDataObject, callback(incomingData));
  expand({'shortUrl':'http://goo.gl/ovZB'}, function(a){
    a = JSON.parse(a);
   console.log('expand: '+a.id + " --\> " +a.longUrl);
  });
  
  //GET API with additonal header
  var expand = apimaker("https://www.googleapis.com/urlshortener/v1/url?shortUrl=&key=&projection=", 'GET', {'User-Agent':'Bond, James Bond'})
  
  
  //a POST API
  var short = apimaker("https://www.googleapis.com/urlshortener/v1/url?longUrl=&key=", "POST");
  
  //google demands we send the data as JSON
  short.enableSendAsJson();
  
  //use it
  //api(oneTimeDataObject, callback(incomingData))
  short({longUrl:"http://news.ycombinator.com/"}, function(a) {
    a = JSON.parse(a);
   console.log('short: '+a.longUrl + " --\> " + a.id)
  });
  
  //PUT
  //docu soon to come
  
  //DELETE
  //docu soont to come
  

magic

  //with an uri like
  //https://www.googleapis.com/urlshortener/v1/url?longUrl=&key=
  //you get
  
  //api.d holds all default-data
  api.d.longUrl
  api.d.key
  
  //getters in setters if you are into that kinda stuff
  //note, these set the default values
  //they stay the same with every request
  api.getLongurl(value)
  api.setLongurl(value)
  
  
  
  

other usefull functions

  //usefull to set callbacks for HTTP 404, 301, ...
  api.addStatusCodeCallback(statusCode, callback)

  //all POST data will be sent as JSON
  //plus with a Content-Type: application/json header
  api.enableSendAsJson()

  //all data will be send as RAW
  //means you have to encode it yourself
  api.enableSendAsRaw()
  
  //add additonal headers to your API requests
  api.setHeader(header, value)

  //a quirks arround method to overwrite the path 
  //for GET/POST mix requests 
  //lets hope you will never need it
  api.setStaticPath(path)
  

TODO

  • encoding of incoming data is currently always UTF8, should be configurable

  • PUT and DELETE examples

  • more docu about the awesome features

  • example use together with node-OAuth

  • support HTTP AUTH (is there an API that sill uses this?)

Keywords

FAQs

Package last updated on 05 May 2011

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