Node Express API - Object Mapper - node.js

We have created a new Node JS API using Express Framework (Typescript as scripting language). This API internally calls an external API. In order to call the external API from within our API, we need to do a translation of the API models to External API Models. Are there any NPM Packages that are available which does the Object to Object mapper?

As i understood your problem i recommend this package which i really find usefull for typescript backends: class-transformer
the github link : https://github.com/typestack/class-transformer#classtoclass
Also automapper-ts is a good choice too: https://github.com/loedeman/AutoMapper
i don't need to explain more than that i think. they have a good docs there. I hope it helps.

Related

GraphQL: Generate static documentation from SDL file

The NPM library graphql-docs will statically generate GraphQL API documentation from a successful schema introspection call against the API server.
I need to similarly generate GraphQL API documentation, but based on an SDL file rather than from an introspection call.
I know I can generate a server stub from my SDL at built time and introspect against that, but this seems like overkill.
Is there a library or a tool-chain, in any language, that makes generating docs from an SDL file simple?
I've messed around with graphdoc before, which can generate static documentation from an SDL file, JSON or even graphql-tools' executableSchema. I don't think there's a lot of other tools out there, since most teams just rely on GraphiQL or GraphQL Playground for their documentation needs.
I recommend https://github.com/2fd/graphdoc to generate a static doc of a GraphQL endpoint.
There are now 2 more recent open source projects to do that.
Magidoc
SpectaQL
Both support creating static docs from SDL files or introspection query.

Undestanding the flow of swagger UI

I am trying to mock the REST API using swagger.. I currently created nodejs project in which the default js appreas which is hello_world.js in ./api/controllers/hello_world.js.
Now I want to create a new controller and want to refer that to my YAML, that is from swaggerUI.. How can I do it? Any link would be much useful.
I am only mocking APIS, not developing.
Many thanks in advance.
Checkout the swagger codegen project, which generates server stubs based on the api specification. Node.js is among the supported languages: https://github.com/swagger-api/swagger-codegen

How do Swagger, Express/Nodejs, Sequelize fit all together in a App

I have some experience in Nodejs/Express, Sequelize and jwt apps.
Recently I started looking at API Designing tools/Specs like RAML -- API Designer, Swagger -- Swagger Tools
I am wondering and I found no article linking or pointing out that how can I use swagger to create/design APIs and then use it in my nodejs/express app which uses Sequelize as an ORM.
JWT functionality is added on to middleware for authentication & authorization.
As I tested so far, I can export nodejs scaffolded app structure from Swagger-Editor using Server Code. On inspection, it actually routes the calls to swagger/YAML files.
How can I use sequelize alongside it?
Also, how do you guys go around from API Spec/Design to App (tools or workflow).
Please point where I am going wrong.
You can take a look at the official documentation here. The docs might be written for v1.7.0 but I can tell you it's still relevant for usage in the latest Sequelize version (I have an actual server running with this design approach).
While your actual app's folder structure might be different due to Swagger's structure, but the way you use Sequelize within your app remains the same.

Sails.js API documentation

I want to develop an API using the MVC pattern. I found sails framework interesting and I'd like to know if it's possible to configure swagger or something like with sails to generate the documentation of my API (something like swagger-express for express for example).
Thanks!
This feature is in progress. If you'd like to help out, we can all collaborate here: https://github.com/balderdashy/sails/issues/1094
Update (August 2015):
Check out this Sails Hook that offers native Swagger integration. It compiles all of the bound routes in Sails, and generates a Swagger 2.0 document: https://github.com/tjwebb/sails-swagger
Here is what I did to have my documentation work with sails.js : you can download swagger-ui here : https://github.com/swagger-api/swagger-ui or via npm (npm install swagger-ui).
Then in the assets folder of your sails project, create a folder that points to the swagger folder ("docs" for example, so you'll be able to access to your documentation via your_url:port/docs)

Node.js-like firebase module for Parse cloud code

I'm trying to integrate Firebase with Parse to add real-time capabilities to my application. However, some API functions (like the ability to limit queries to Firebase with limit() or startAt()/endAt()) are not available with the firebase REST API.
They are available with the Node.js module, but even though Parse Cloud support CommonJS-like modules, I'm not sure it's possible to integrate the Firebase node module without some major tweaking.
Any idea how I could access these functions, other than running my own node.js server with the Firebase plugin and using it to redirect my calls to firebase?
It looks like it's possible. What you'll want to do is create a "Cloud Code Module" and wrap the Firebase tools you need. They have a tutorial here
It's pretty standard node.js structures. You put all your Firebase methods into exports, add an initialize method (this is where you'd probably do things like auth?), and you're off.
Wrapping Firebase isn't hard or lengthy. Here's a gist that wraps Firebase in a promise structure, for example. You could basically take the methods from that gist as a blueprint for wrapping them into Parse.
I find it not easy, firebase is dependent on faye-websocket and in its turn requires other libs. We can make it work using "Cloud Code Module" but I don't like adding libs this way.
This is a request for Parse to support node modules, unfortunately the answer is a flat NO from them for now https://parse.com/questions/using-npm-modules-in-cloud-code.
Would appreciate any update on this. Thanks!

Resources