
Research
/Security News
Toptal’s GitHub Organization Hijacked: 10 Malicious Packages Published
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.
This is a REST API for yocto
All http requests that are implemented by the yocto rest api :
Important : to use yocto-api, you should use the midlleware cors for express : https://www.npmjs.com/package/cors
Apidoc is a tool that permit to generate documentation of our REST API from comments https://github.com/apidoc/apidoc
You should add this main params in your package.json
SampleUrl is the main url of your api, this params will be use in each method you will define
"apidoc": {
"title": "Yocto Rest Api",
"sampleUrl": "http://localhost:8080/api",
"url": "http://localhost:8080/api"
}
Apidoc generator is a little module that read each model file and create a comments file that will be used by apidoc
'use strict';
var express = require('express'); // Load express
var bodyParser = require('body-parser'); // load bodyparser
var mongoose = require('mongoose'); // Load the mongodb driver
var routes = require('./app/routes/controller.js'); // Load the api
var app = express(); // Create app
// connect to our database
mongoose.connect('mongodb://localhost:27017');
// configure app to use bodyParser()
app.use(bodyParser.urlencoded({ extended : true }));
app.use(bodyParser.json());
// set our port
var port = process.env.PORT || 8080;
//Initialise the API router
routes.init();
//Use the router
app.use('/api', routes.router);
// START THE SERVER
app.listen(port);
Each Model is defined in one json file.
In this file an object "apidoc" is also declared to generate the doc automatically
The structure of the json is as follows :
{
"models" : {
"model" : {}
},
"apidoc" : {
"methods" : []
}
}
A model have means a name, and one properties
Each properties can be a type, required or/and an array.
"model" : {
"name" : "user",
"properties" : {
"firstname" : {
"type" : "String",
"required" : true
}
}
}
"model" : {
"name" : "user",
"properties" : {
"firstname" : "String"
}
}
"model" : {
"name" : "user",
"properties" : {
"cart_id" : ["ObjectId"]
}
}
"model" : {
"name" : "user",
"properties" : {
"category_id" : [
{
"type" : "ObjectId",
"required" : true
}
]
}
}
{
"models" : {
"model" : {
"name" : "product",
"properties" : {
"name" : {
"type" : "String",
"required" : true
},
"reference" : {
"type" : "String",
"required" : true
},
"availability_id" : ["ObjectId"],
"category_id" : [{
"type" : "ObjectId",
"required" : true
}
]
}
}
},
"apidoc" : {}
}
An apidoc object can have lot of http methods, each method will create a new item in the doc
All this params are required :
This array of object define all param you want add and which are not present in model.
You can specify if it's required
"methods" : [
{
"apiVersion" : "0.1.0",
"type" : "get",
"title" : "GET product(s)",
"path" : "/product/:product_id",
"apiPermission" : "admin",
"addDefaultParamFromModel" : false,
"methodDescription" : "Method to retrieve one or all product, if you want get one product you should specify his id, otherwise the whole products are returned",
"specificParam" : [
{
"name" : "product_id",
"type" : "Object_id",
"required" : true
}
],
}
]
This define the response that you will receive if your request is a success
They have default apiSuccess, you can call it by :
"methods" : [
{
"apiVersion" : "0.1.0",
"type" : "get",
"title" : "GET product(s)",
"path" : "/product/:product_id",
"apiPermission" : "admin",
"addDefaultParamFromModel" : false,
"methodDescription" : "Method to retrieve one or all product, if you want get one product you should specify his id, otherwise the whole products are returned",
"apiSuccessExample" : "success"
}
]
Or specify you own response :
"methods" : [
{
"apiVersion" : "0.1.0",
"type" : "get",
"title" : "GET product(s)",
"path" : "/product/:product_id",
"apiPermission" : "admin",
"addDefaultParamFromModel" : false,
"methodDescription" : "Method to retrieve one or all product, if you want get one product you should specify his id, otherwise the whole products are returned",
"apiSuccessExample" : {
"name" : "Success-Response",
"addDefaultParamFromModel" : true,
"example" : {
"header" : "HTTP/1.1 200 OK"
}
}
}
]
This define the response that you will receive if your request is a an error
They have default apiErrorrExample, you can call it by :
"methods" : [
{
"apiVersion" : "0.1.0",
"type" : "get",
"title" : "GET product(s)",
"path" : "/product/:product_id",
"apiPermission" : "admin",
"addDefaultParamFromModel" : false,
"methodDescription" : "Method to retrieve one or all product, if you want get one product you should specify his id, otherwise the whole products are returned",
"apiErrorrExample" : "notFound"
}
]
Or specify you own response :
"methods" : [
{
"apiVersion" : "0.1.0",
"type" : "get",
"title" : "GET product(s)",
"path" : "/product/:product_id",
"apiPermission" : "admin",
"addDefaultParamFromModel" : false,
"methodDescription" : "Method to retrieve one or all product, if you want get one product you should specify his id, otherwise the whole products are returned",
"apiErrorrExample" : {
"name" : "Success-Response",
"addDefaultParamFromModel" : true,
"example" : {
"header" : "HTTP/1.1 400 NOT OK"
}
}
}
]
You can add multiple routes in the json file
You can add alias for the main Object of the url (it's useful for plurial)
By default all http request are implemented, you can exclude each request
You can specify the name of one parameter to retrieve in the url
You should specify the name of the model that you want use
{
"routes" : [
{
"path" : "/users/:user_id",
"alias" : ["user"],
"model" : "User",
"paramToRetrieve" : "user_id",
"requestExcluded" : ["post"]
}
]
}
FAQs
Yocto REST API
The npm package yocto-api receives a total of 12 weekly downloads. As such, yocto-api popularity was classified as not popular.
We found that yocto-api demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
/Security News
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.
Research
/Security News
Socket researchers investigate 4 malicious npm and PyPI packages with 56,000+ downloads that install surveillance malware.
Security News
The ongoing npm phishing campaign escalates as attackers hijack the popular 'is' package, embedding malware in multiple versions.