summaryrefslogtreecommitdiff
path: root/paths.js
diff options
context:
space:
mode:
authorGeorge Halkiadakis <gchalkiadakis@sklavenitis.co.gr>2024-04-09 01:39:07 +0300
committerGeorge Halkiadakis <gchalkiadakis@sklavenitis.co.gr>2024-04-09 01:39:07 +0300
commitf52ea6691ad26aac0a5b4b4f6e292492a8f2a2da (patch)
treed10488153c162a3ec6b222b76f3f6182ce8d7cf6 /paths.js
downloadoseine-f52ea6691ad26aac0a5b4b4f6e292492a8f2a2da.tar.gz
oseine-f52ea6691ad26aac0a5b4b4f6e292492a8f2a2da.tar.bz2
oseine-f52ea6691ad26aac0a5b4b4f6e292492a8f2a2da.zip
basic node.js+koa rest api installation
Diffstat (limited to 'paths.js')
-rw-r--r--paths.js53
1 files changed, 53 insertions, 0 deletions
diff --git a/paths.js b/paths.js
new file mode 100644
index 0000000..9de584c
--- /dev/null
+++ b/paths.js
@@ -0,0 +1,53 @@
+const Router = require('koa-router');
+
+// Prefix all routes with: /items
+const router = new Router({
+ //// prefix: '/items'
+});
+
+// let items = [
+// { id: 100, iname: 'Quartz Analog Wrist Watch', price: 'US $4.99'},
+// { id: 101, iname: 'Leather Peep Pump Heels', price: 'US $33.56'},
+// { id: 102, iname: 'Apple iPod', price: 'US $219.99'},
+// { id: 103, iname: 'Prince Phantom 97P Tennnis Racket', price: 'US $50.00'},
+// ];
+
+
+// Routes
+
+/// router.get('/items', (ctx, next) => {
+/// ctx.body = items;
+/// next();
+/// });
+///
+/// router.get('/items/:id', (ctx, next) => {
+/// let getCurrentItem = items.filter(function(item) {
+/// if (item.id == ctx.params.id) {
+/// return true;
+/// }
+/// });
+///
+/// if (getCurrentItem.length) {
+/// ctx.body = getCurrentItem[0];
+/// } else {
+/// ctx.response.status = 404;
+/// ctx.body = 'Item Not Found';
+/// }
+/// next();
+/// });
+
+router.get('/search', (ctx, next) => {
+ ctx.body = [];
+ next();
+});
+
+router.get('/search/:title', (ctx, next) => {
+ let words = ctx.params.title.split(' ');
+ ctx.body = {
+ params: ctx.params,
+ results: words
+ };
+ next();
+});
+
+module.exports = router; \ No newline at end of file