:art: JavaScript and REST APIs

:art: JavaScript and REST APIs

- 1 min

There are several Web services available on the internet. Many web services, like Twilio and Facebook, make their data accessible to third-party applications through an application programming interface (API). One of the most popular ways to build APIs is the REST(REpresentational Stateless Transfer) architecture style.

This post will be a good primer for a Java programmer looking to integrate any web-service APIs.

In this post, I shall show a working source code and a docker container image to get started quickly.

Use below two commands to see the example in action.

make build-container 
make test-container

Purpose

Provide a sample example code for RESTful Web Services in JavaScript.

Installation

Please refer to Makefile and Dockerfile for install and build instructions.

    make install
    make build
    make build-container

Resource

ExpressJS is one of the most popular HTTP server libraries for Node.js

Restful Methods

  1. POST
     app.post('/event', function (req, res))
    
  2. GET
     app.get('/', function (req, res))
     app.get('/events/:id', function (req, res))
     app.get('/listUsers', function (req, res))
    
  3. PATCH
     app.patch('/events/:id', function (req, res))
    
  4. DELETE
     app.delete('/events/:id', function (req, res))
    

Testing

Next Steps

Follow the below links for the source code and Dockerfile

Example Source Code

README.md

Makefile

Docker Image

I hope that these references will make getting started extremely easy.

Enjoy!

Web Resources

Satya Dillikar

Satya Dillikar

Hands-on Software Architect with extensive experience developing and delivering distributed enterprise-class mission-critical software applications.

DISCLAIMER: All views expressed on this site are my own and do not represent the opinions of any entity whatsoever with which I have been, am now, or will be affiliated. Any collateral used is referenced in the Web Resources or others sections on this page. The information provided on this website does not constitute investment advice, financial advice, or trading advice.

comments powered by Disqus