npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@zohodesk/js-api-creator

v1.0.24

Published

This is used for server side api call as js api call in client side - js-api-creator javascript es6

Downloads

505

Readme

1.0.21

We changed xhrAPI method to support payload encryption flow

1.0.19,1.0.20

We changed the medthod delete allowing the payloads progressReport - undeclare variable fix added.

#js-api-creator

##How to install

 npm i js-api-creator deletions

##How to use

For example server urls : https://myspace.com/space/v1/connectBlogs, https://myspace.com/space/v1/connectBlogs/:id

Check the below, how to convert the server api's as json format.

Note :notebook: No need to add this https://myspace.com/space/v1/ prefix for all your api.Just add connectBlogs,connectBlogs/:id.


import { constants } from 'js-api-creator'; 

let jsonAPIS = {
	"blogs" : { url : "connectBlogs" , method : constants.get } ,
	"blogs.create" : { url : "connectBlogs" , method : constants.post } ,
	"blogs.deleteIt" : { url : "connectBlogs/:id" , method : constants.deleteIt } ,
	"blogs.update" : { url : "connectBlogs/:id" , method : constants.put }  ,
	"blogs.get" : { url : "connectBlogs/:id" , method : constants.get },
	"blogs.getByPermalink" : { url : "connectBlogs/blogByPermalink", method : constants.get } ,
	"blogs.search" : { url : "connectBlogs/search", method : constants.get },
	"blogs.relatedBlogs" : { url : "connectBlogs/relatedArticleSearch" , method : constants.get } ,
	"blogs.like" : { url : "connectBlogs/:id/like", method : constants.post },
	"blogs.disLike" : { url : "connectBlogs/:id/dislike", method : constants.post } ,
	"blogs.attachments" : { url : "connectBlogs/:id/attachments", method : constants.get } ,
	"blogs.attachments.download" : { url : "connectBlogs/:blogId/attachments/:id/content" ,
									 method : constants.download }  ,
	"blogs.updateFeedback" : { url : "connectBlogs/:id/feedbacks", method : constants.post } ,
	"blogs.comments" : { url : "connectBlogs/:id/comments" , method : constants.get},
	"blogs.comments.get" :{ url : "connectBlogs/:id/comments/:id", method : constants.get },
	"blogs.comments.attachments" :{ url : "connectBlogs/:blogId/comments/:id/attachments", method : constants.get },
	"blogs.comments.attachments.download" : { url : "connectBlogsBlogs/:blogId/comments/:commentId/attachments/:id/content" , 
										method : constants.download } ,
	"categories" : { url : "connectCategory" , method : constants.get }
}

###Now we created a json format of all our api's.

##How to handle the multiple id's in same url path. Example URL : https://myspace.com/space/v1/connectBlogsBlogs/:blogId/comments/:commentId/attachments/:id/content

     let jsonAPIS = {
         "blogs.comments.attachments.download" : { 
		url : "connectBlogsBlogs/:blogId/comments/:commentId/attachments/:attachmentId/content" ,
		method : constants.download
         }
     }

###How to pass the multiple id's to the api :

    
     blogs.comments.attachments.download({
        blogId : 'efgh-abcd',                    ===> refers blog id
     	commentId : 'abcd-efgh',                 ===> refers comment id
     	attachmentId : 'xyz-pqrs'                ===> refers attachment id
     })

###URL output will be :

    `https://myspace.com/space/v1/connectBlogsBlogs/efgh-abcd/comments/abcd-efgh/attachments/xyz-pqrs/content`

##Example - how to create server api's for your app using APIBuilder class.

#modueName - used for return the converted api's with this given name.

#jsonAPIS - variable json object, we have already created above.

import APIBuilder from 'js-api-creator'; 
let apiBuilder = new APIBuilder( 
	   (`moduleName`)=>"https://myspace.com/space/v1/" ,   ===> url prefix will be added for all urls
	   (`moduleName`)=>globalParameters,                   ===> global params will be added for all urls
	   (`moduleName`)=>headers                             ===> global header will be added for all urls
	);


let apiModuleObject = apiBuilder.create( `jsonAPIS` , `modueName`);


#Output : how to call the api.

apiModuleObject.`modueName`.blogs( parameters as json , resolve/success , reject/failure ) 
apiModuleObject.`modueName`.blogs.Get( parameters as json , resolve/success , reject/failure  ) 
apiModuleObject.`modueName`.blogs.Search( parameters as json , resolve/success , reject/failure )
apiModuleObject.`modueName`.categories( parameters as json, resolve/success , reject/failure  )
  

###If you want override the url for Specifically, when calling the api?.

	apiModuleObject.`modueName`.blogs( { url } , parameters , resolve , reject );

###If you want override the header for Specifically, when calling the api?.

	apiModuleObject.`modueName`.blogs( { header } , parameters , resolve , reject );

###To change the global url prefix, parameters and header for Specifically.You can use modueName in APIBuilder class.

 new APIBuilder( 
	 	(`modueName`)=>{

	 	   if(`modueName` == "kb"){
	 	   	 return module-specific-url-prefix as string
	 	   }
	 	   
	 	   return common-url-prefix as string

	 	},
	 	
	 	(`modueName`)=>{
	 	   if(`modueName` == "kb"){
	 	   	 return {module-specific-global-parameters}
	 	   }
	 	   
	 	   return {common-global-parameters} as json

	 	},

	 	(`modueName`)=>{

	 	   if(`modueName` == "kb"){
	 	   	 return {module-specific-headers}
	 	   }
	 	   
	 	   return {common-global-headers} as json
	 	}
	 );