APIOps / apiops-meetup-website

Apiops Meetup Website
http://apiops.net
MIT License
0 stars 0 forks source link

API for events #9

Open kyyberi opened 8 years ago

kyyberi commented 8 years ago

From @kyyberi on October 17, 2015 8:41

As a developer I want to access events via API to show details in other contexts.

Copied from original issue: APIOps/portal#27

kyyberi commented 8 years ago

I started Swagger 2.0 based description of the API to https://github.com/APIOps/portal/blob/master/API/spec.yaml

kyyberi commented 8 years ago

Tested the process and now docs are available at http://www.apiops.net:8088/docs

kyyberi commented 8 years ago

Requires some manual work to get documentation to work. had to manually edit generated nodejs code nodejs-server/api/swagger.json. Replace localhost in "host": "apiops.net:8088", [http://www.apiops.net:8088/api-docs] to get api call to go to correct url, not localhost.

Also I replaced localhost from index.js. In addition variable port is not used anywhere (obsolete):

var app = require('connect')();
var http = require('http');
var swaggerTools = require('swagger-tools');

var serverPort = 8080;

// swaggerRouter configuration
var options = {
  swaggerUi: '/swagger.json',
  controllers: './controllers',
  useStubs: process.env.NODE_ENV === 'development' ? true : false // Conditionally turn on stubs (mock mode)
};

// The Swagger document (require it, build it programmatically, fetch it from a URL, ...)
var swaggerDoc = require('./api/swagger.json');

// Initialize the Swagger middleware
swaggerTools.initializeMiddleware(swaggerDoc, function (middleware) {
  // Interpret Swagger resources and attach metadata to request - must be first in swagger-tools middleware chain
  app.use(middleware.swaggerMetadata());

  // Validate Swagger requests
  app.use(middleware.swaggerValidator());

  // Route validated requests to appropriate controller
  app.use(middleware.swaggerRouter(options));

  // Serve the Swagger documents and Swagger UI
  app.use(middleware.swaggerUi());

  // Start the server
  http.createServer(app).listen(8088, function () {
    console.log('Your server is listening on port %d (http://apiops.net:%d)', 8088, 8088);
    console.log('Swagger-ui is available on http://apiops.net:%d/docs', 8088);
  });
});
kyyberi commented 8 years ago

I also needed to install nodejs and npm. With npm I installed connect and swagger-tools modules. There has to be automated way to do this since dependencies are listed in package.json

jarkko@APIOps:~/nodejs-server$ more package.json 
{
  "name": "",
  "version": "0.0.1",
  "description": "A simple API for retrieving APIOps events information (swagger-2.0 specification)",
  "main": "index.js",
  "keywords": [
    "swagger"
  ],
  "license": "MIT",
  "private": true,
  "dependencies": {
    "connect": "^3.2.0",
    "swagger-tools": "0.8.*"
  }
}

Ok. It should be simple as "npm install" :) That should install all dependencies.