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 📓 No need to add this https://myspace.com/space/v1/
prefix for all your api.Just add connectBlogs
,connectBlogs/:id
.
; let jsonAPIS = "blogs" : url : "connectBlogs" method : constantsget "blogs.create" : url : "connectBlogs" method : constantspost "blogs.deleteIt" : url : "connectBlogs/:id" method : constantsdeleteIt "blogs.update" : url : "connectBlogs/:id" method : constantsput "blogs.get" : url : "connectBlogs/:id" method : constantsget "blogs.getByPermalink" : url : "connectBlogs/blogByPermalink" method : constantsget "blogs.search" : url : "connectBlogs/search" method : constantsget "blogs.relatedBlogs" : url : "connectBlogs/relatedArticleSearch" method : constantsget "blogs.like" : url : "connectBlogs/:id/like" method : constantspost "blogs.disLike" : url : "connectBlogs/:id/dislike" method : constantspost "blogs.attachments" : url : "connectBlogs/:id/attachments" method : constantsget "blogs.attachments.download" : url : "connectBlogs/:blogId/attachments/:id/content" method : constantsdownload "blogs.updateFeedback" : url : "connectBlogs/:id/feedbacks" method : constantspost "blogs.comments" : url : "connectBlogs/:id/comments" method : constantsget "blogs.comments.get" : url : "connectBlogs/:id/comments/:id" method : constantsget "blogs.comments.attachments" : url : "connectBlogs/:blogId/comments/:id/attachments" method : constantsget "blogs.comments.attachments.download" : url : "connectBlogsBlogs/:blogId/comments/:commentId/attachments/:id/content" method : constantsdownload "categories" : url : "connectCategory" method : constantsget
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 : constantsdownload
#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`
APIBuilder
class.
Example - how to create server api's for your app using modueName
- used for return the converted api's with this given name.
jsonAPIS
- variable json object, we have already created above.
; let apiBuilder = "https://myspace.com/space/v1/" ===> url prefix will be added for all urls `I have already mentioned` globalParameters ===> global params will be added for all urls headers ===> global header will be added for all urls ; let apiModuleObject = apiBuilder; #Output : how to call the api apiModuleObject`modueName` apiModuleObject`modueName`blogs apiModuleObject`modueName`blogsapiModuleObject`modueName`
when calling the api?
.
If you want override the url for Specifically, apiModuleObject`modueName`;
when calling the api?
.
If you want override the header for Specifically, apiModuleObject`modueName`;
url prefix
, parameters
and header
for Specifically.You can use modueName
in APIBuilder
class.
To change the global { if`modueName` == "kb" return module-specific-url-prefix as string return common-url-prefix as string } { if`modueName` == "kb" return module-specific-global-parameters return common-global-parameters as json } { if`modueName` == "kb" return module-specific-headers return common-global-headers as json } ;