I have a npm-based project and I want to introduce swagger-based REST API client into it. My idea is to have API description yaml file and generate client on build step.
Is there any well knows approaches to do it? I found only swagger-js-codegen but I don't clearly understand how to integrate it into building process.
Given that you've your REST API documented in Swagger/OpenAPI spec, you can then simply use curl (or other http tools) to send an HTTP request to generate API clients as part of your build process. An example of the curl request to generate ruby client for http://petstore.swagger.io/v2/swagger.json is as follows:
curl -X POST -H "content-type:application/json" -d '{"swaggerUrl":"http://petstore.swagger.io/v2/swagger.json"}' https://generator.swagger.io/api/gen/clients/ruby
Please refer to https://github.com/swagger-api/swagger-codegen#online-generators for more info.
UPDATE: On May 2018, about 50 top contributors and template creators of Swagger Codegen decided to fork Swagger Codegen to maintain a community-driven version called OpenAPI Generator. Please refer to the Q&A for more information.
Related
I have a doubt, suppose, I made a React project using npx create-my-app myProject
and in this public folder, I have several folders having NodeJS for Postgres database.
so, my question is if I have to load data from postgres to react component, how will I do it? can I do it using axios? if not then how?
if yes, how will I test it? suppose, my backend nodejs postgres is online, and I am using my react on local:3000, how will I test it, if postgres has get function is like /api/xyz
?
You really should not do this in the Frontend (=React) part of you application.
This would open the door to some serious security issues, as you would have to establish a connection to the database from the client, and in order do so, have to save the databases credentials there. It would be relatively easy for any attacker to get this data.
Basically, create a backend server (maybe with nodejs), create a connection there to postgres, fetch the requested data there and send it to the client. You can use axios for that or any other http library like fetch. Your frontend can run on localhost:3000 and the backend on localhost:4000. Here is a tutorial you can follow.
I'm using the NodeJS https module to fetch pages and process them during testing. I can't find any mention of following redirects either there or in the http module documentation.
From experience I would assume that an https.request does not automatically follow redirects (through response.headers.Location), but I'd like to be sure.
Nodejs doesn't follow redirects by default.
The following article explains this http://syskall.com/how-to-follow-http-redirects-in-node-dot-js/
I have kafka set up on my machine with schema registry enabled.
I am also writing a Flask application on my same machine.
I need to access the Rest API i.e.
localhost:8081/schemas/ids/1
From
localhost:5000
How do I achieve this?
I am using latest version of kafka and schema registry.. and have tried using JavaScript CORS request
EDIT
Here is the properties file
Here is the code
Here is the error
Here is the logs
Add the following config parameters to your etc/schema-registry/schema-registry.properties file to enable CORS
access.control.allow.methods=GET,POST,PUT,OPTIONS
access.control.allow.origin=*
Full documentation for config params is here http://docs.confluent.io/current/schema-registry/docs/config.html
I am trying to integrate npm's application insights module (https://www.npmjs.com/package/applicationinsights) into my React js application.
My source for doing this is:
import appInsights from 'applicationinsights';
appInsights.setup(applicationInsightsKey).start();
The problem I got is that in my Chrome Developer tools I can see a preflight request made to https://dc.services.visualstudio.com/v2/track.
But in the console I can see the following error:
"Fetch API cannot load https://dc.services.visualstudio.com/v2/track.
Request header field content-encoding is not allowed by
Access-Control-Allow-Headers in preflight response."
Do you have an idea how can I fix this issue?
The node.js module you are using is the AI SDK for Node.js server. And As the React js applications are client applications in javascript, technically they are different.
Please try to use ApplicationInsights-JS.
Additionally, you can refer to https://azure.microsoft.com/en-us/documentation/articles/app-insights-web-track-usage/ for more info.
This is probably a really basic question.
I'm new to node.js.
I'm writing a script which receives an HTTP POST request. I'm going to be deploying to Heroku, but while I'm testing locally how do I make POST requests to the script?
Thanks.
You can use chrome extension called postman.
If you're on unix (OSX, Linux, BSD) or have an environment where you can download/use unix tools (cygwin, git bash) you can use curl:
curl -XPOST http://localhost/my/app -d 'data you want to post'
If you're using Google Chrome or you're on a Mac install Postman