diff --git a/src/http-api/resources/block.js b/src/http-api/resources/block.js index e69de29bb2..0c3fdef139 100644 --- a/src/http-api/resources/block.js +++ b/src/http-api/resources/block.js @@ -0,0 +1,39 @@ +'use strict' + +const ipfs = require('./../index.js').ipfs +// const debug = require('debug') +// const get = require('lodash.get') +// const set = require('lodash.set') +// const log = debug('http-api:config') +// log.error = debug('http-api:config:error') +// const multipart = require('ipfs-multipart') + +exports = module.exports + +exports.get = (request, reply) => { + ipfs.block.get((multihash, callback) => { + // parseargs to make sure it is a Multihash + return reply(callback) + }) +} + +exports.put = (request, reply) => { + ipfs.block.put((multihash, callback) => { + // parseArgs to make sure it is a block + return reply(callback) + }) +} + +exports.del = (request, reply) => { + ipfs.block.del((multihash, callback) => { + // parseargs to make sure it is a Multihash + return reply(callback) + }) +} + +exports.stat = (request, reply) => { + ipfs.block.stat((multihash, callback) => { + // parseargs to make sure it is a Multihash + return reply(callback) + }) +} diff --git a/src/http-api/routes/block.js b/src/http-api/routes/block.js index 570365ea0d..f6e8889e76 100644 --- a/src/http-api/routes/block.js +++ b/src/http-api/routes/block.js @@ -1,10 +1,55 @@ const api = require('./../index.js').server.select('API') const resources = require('./../resources') +const Joi = require('joi') -// TODO +api.route({ + method: 'GET', + path: '/api/v0/block/get/{arg?}', + handler: resources.block.get, + config: { + validate: { + query: { + arg: Joi.string().required() // The base58 multihash of an existing block to get. + } + } + } +}) + +api.route({ + method: 'POST', + path: '/api/v0/block/put/{arg?}', + handler: resources.block.put, + config: { + validate: { + query: { + arg: Joi.string().required() // The data to be stored as an IPFS block. + } + } + } +}) + +api.route({ + method: 'DELETE', + path: '/api/v0/block/del/{arg?}', + handler: resources.block.del, + config: { + validate: { + query: { + arg: Joi.string().required() // The base58 multihash of the IPFS block to be removed. + } + } + } +}) api.route({ method: 'GET', - path: '/api/v0/block', - handler: resources.block + path: '/api/v0/block/stat/{arg?}', + handler: resources.block.stat, + config: { + validate: { + query: { + arg: Joi.string().required() // The base58 multihash of an existing block to get. + } + } + } })