Create Swagger-docs for API written in Express 4.x - javascript

I have a server written with Node and Express 4. I also have a customer which wants this to be documented with Swagger. How can this be done?
I've looked into the following tools:
swagger-node-express: Lets you do exactly what I want, except it does not support Express 4.x
Swagger 2.0 - Node-Express-4.x: Same as above but with a different approach. Could be used, except I don't find much documentation on setting it up (and I'm too slow to get it without docs)
Tools like swaggerize-express and Swaggers own tool for Node would work if I started from scratch, but I just want a way to easiliy add docs to my project so that Swagger can read it.
It wouldn't work in the long run to write a doc-file that Swagger can read because then I'd have to update it. I want to document everything in the code and not a Swagger- or readme-file, and let the documentation be available through a Swagger-UI automatically.
I may have overlooked something here, but I can't seem to find anything to help me.All suggestions are welcome. Thanks in advance.

I highly recommend looking into Loopback framework. It's framework for creating REST APIs on stereoids. It is using Express under the hood and is created by company StrongLoop, which also maintains Express project itself now.
It supports Swagger out of the box.

Related

Use Typescript and nodejs to create a app that is not web or api?

Is appropriate to use nodejs and typescript to make a service that is not an API or web application? Currently, I'm making a service who periodically read emails attachments and send the attachments to another app, save info about the emails in db etc.. It's working good, but i can't find in the internet examples of structure of a non-web app with typescript
What you think? I know it is possible because I have already done... But is appropriate? Do you have some examples where I can check? Cant find in GitHub either, I don't know how to call an app like this
Sounds like you have a CLI tool?
Maybe these repos could give you some help with structure/practices:
https://github1s.com/sindresorhus/trash
https://github1s.com/sindresorhus/speed-test
https://github1s.com/MrRio/vtop
https://github1s.com/millermedeiros/esformatter
https://github1s.com/gustavofabro/get-torrents-cli
https://www.google.com/search?q=most+popular+node+js+cli+tools
https://www.npmjs.com/search?q=cli
Typescript is an excellent choice for one-off scripting and CLI tools IMO.

javascript object2object mapper

I'm searching for a javascript mapping library I can easily integrate in my angularjs project.
I use some json objects in my javascript code that are slightly different from the json structure given by my back-end.
I have found this interesting library (https://github.com/wankdanker/node-object-mapper) that lets you specify a mapping through another object, but unfortunately it seems to work only in a nodejs environment and not in the browser.
Does anyone know a similar library working in a browser too?
Last year, I have created a port of the C# AutoMapper implementation to TypeScript / JavaScript exactly for this scenario. I have put the code at GitHub (https://b.ldmn.nl/AutoMapperTS). You can also use the library directly using the automapper-ts NPM or Bower package.
The library is almost fully documented. Furthermore, quite a lot of Jasmine unit tests are already available (code coverage is about 95%). They should provide you with some explanation of what you need.
I hope this library suits your needs. Should you have any questions and/or remarks, please don't hesitate contacting me!

Ember.js + Ember Data + PostgreSQL

I'm having trouble understanding how to connect Ember.js with PostgreSQL using Ember Data adapter.
My main problem is finding a complete example where I can study how I would do this.
I know I have to create a jsonapi to provide the data. My goal is using Node.js to provide the data.
I've found this project here and I see that it has a relational db store.
Anyone knows where I can find a complete example of a project using Ember with a PostgreSQL jsonapi server implemented in Node.js?
Preferably a simple project where I can understand the basics of getting a connection running and show the data in Ember.
Any help appreciated. :)
I've written a boilerplate node app and a boilerplate ember app that are designed to work together as a frontend/backend app. They aren't especially simple, but if you explore them you might be able to gain some good insight into how these two frameworks can connect.
For example, in the users controller, the show method maps to /users/:id, and then responds with a custom JSON payload conforming to JSON API spec. Although it hasn't been implemented yet, in Ember simply having this.store.findRecord('user', 1) will automatically send a request to /users/1.
You can explore the config files to look at the postgres connection (I implemented using bookshelf and knex).
Hope that helps!
You actually have two questions here. You first need to choose how nodejs communicates with your ember-data. This is a possible approach. It also provides a connector to your database.
Secondly, you need to define how nodejs communicates with the db. Here is a list of possible packages that might fit your needs.

How to secure Node.js connect-rest REST API with OAuth?

I tried Googling around for some examples, or well anything, but couldn't find any results. I think partially because the name of the package "connect-rest" is so generic.
Anyway, here is what i'm looking to do. I am using the Node module "connect-rest" to build a server side API. It is mostly finished at this point, and i'm now looking to secure it. Now the module itself has a system of authentication with API Keys, which is well and fine, but not very secure for Javascript clients, since anyone could just browse the source and grab the key. And trying to secure a key -- well it just doesn't work without getting super complicated.
So instead i'd rather use a standard OAuth setup. I was hoping to use Passport in combination with connect-rest and wondering if anyone has done this before or point me to some examples?
I found exactly what I needed with OAuthorize: https://github.com/jaredhanson/oauthorize which is written by the same guy as Passport.
We used the following guide for our own learning when we started a similar process: http://scotch.io/tutorials/javascript/easy-node-authentication-setup-and-local
Also take a look at MeanJS. It has a built in authentication/user system.

Spoofing an API with SinonJS?

When developing an API (in my case an API that wraps around a websockets service), is there a good way of giving it's skeletal implementation to another developer so that he can work independent of me? If my API is still in the design phase for example, I'm thinking that I could give an outline of the methods that will be available and all the possible return types.
I realise that I could just give him a dummy object with all the methods inside but it would be great if that dummy object could be tied in with his unit tests and so on.
I've been looking at [SinonJs][1]: http://sinonjs.org/ and in particular at the Stub functionality it provides. However I am not sure if what I've outlined here is an appropriate use of stubs.
Any advice appreciated!
EDIT:
I guess this question should of been:
'How to write unit tests using Jasmine, Sinon and a mock API'
It was a bit of a silly question because it turns out that Sinon actually has it's own 'fake server' which is very easy to use. In ignorance of this my first idea was to mock or spy on XHR stuff.
The code I ended up with is here: https://gist.github.com/james-gardner/11405316
See 'DummyViewSpec.js' for examples of the fake server stuff. Edits welcome!
If you are asking about an easy way to have a web app (or other REST) API up and running - http://flatironjs.org/ might be a good option for you. It's full JS stack both on the server (node.js) and client. However, you can do an API mockups with any other routing library (search npm - there are A LOT of them).
I hope it helps.
There is a tool to mockup the whole APIs using schema and random data with types
https://github.com/homerquan/kakuen
I created and used it to inject dependance of api

Categories

Resources