npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-japi

v1.0.6

Published

JAPI Microservice

Downloads

8

Readme

JAPI Microservice

JAPI - микросервис и протокол обмена данными между клиентом и сервером на основе формата JSON.

Данные в формате JSON (метод POST) передаются в едину точку (хост) обработки запросов микросервиса, например: http://127.0.0.1:30000, после обработки запроса возвращается ответ в формате JSON.

Объект запроса

japi

Версия JAPI приложения.

app

Объект приложения.

let app = {
  '1.0.0': {
    getUser: () => {
      // Function body
    }
  }
}

method

Вызываемый метод API.

let japi = {
  japi: "1.0.0",
  method: "getUser",
  app: app
}

Вызывает метод getUser объекта приложения app версии 1.0.0

params

Параметры запроса: object, array, null или может отсуствовать если запрос без параметров.

Объект ответа

Ошибки

  • 1 - Option "japi" or "method" is not set
  • 2 - Object not found
  • 3 - Method not found
  • 4 - Validation error
  • > 99 - Application error

При success:true может присутствовать result, при success:false обязательным будет присутствие error

{
  "success": true,
  "result": [{
    "uid": 5,
    "name": "Roman Sopov",
    "email": "[email protected]"
  }]
}
{
  "success": false,
  "error": {
    "code": 100,
    "message": "Ошибка в параметрах запроса"
  }
}

Пример

const _japi = require('node-japi');
const japi = _japi.japi;
const req  = _japi.req;

const app = {
  '1.0.0': require('./app')
};

japi({
  name: 'japi-test',
  host: '127.0.0.1',
  port: 30000,
  app:  app
}).then(server => {
  // server - https://nodejs.org/dist/latest-v6.x/docs/api/http.html#http_class_http_server 
  let p1 = req('http://127.0.0.1:30000', {
    japi:   "1.0.0",
    method: "test",
    params: {
      test: 1
    }
  });
  let p2 = req('http://127.0.0.1:30000', {
    japi:   "1.0.1",
    method: "test",
    params: {
      test: 1
    }
  });
  let p3 = req('http://127.0.0.1:30000', {
    japi:   "1.0.0",
    method: "test2",
    params: {
      test: 1
    }
  });
  let p4 = req('http://127.0.0.1:30000', {
    japi:   "1.0.0",
    method: "test",
    params: {
      test: '2'
    }
  });
  let p5 = req('http://127.0.0.1:30000', {
    japi:   "1.0.0",
    method: "test",
    params: {
      test2: 1
    }
  });

  Promise.all([p1, p2, p3, p4, p5]).then(values => {
    /* console.log(values);
    [ 
      { success: true, result: true },
      { success: false, error: { code: 2, message: 'Object not found' } },
      { success: false, error: { code: 3, message: 'Method not found' } },
      { success: false, error: { code: 100, message: 'Validation Error: option "test" not equal 1' } },
      { success: false, error: { code: 100, message: 'Validation Error: option "test" is undefined' } } 
    ]
    */
    server.close();
  });
  
});

Используемая документация

http://json.org/
http://jsonapi.org/
http://jsonrpc.org/