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

@stjohnd777/easyrest

v1.0.4

Published

Install ```js npm install @stjohnd777/easyrest ``` ### Overview - uses express - will create express instance if not provided - will piggyback on express instance if provided - provides heart beat service /ping - supports http and https - stand

Downloads

3

Readme

##EasyRest

REST framework for implementing REST service.

Install

npm install @stjohnd777/easyrest

Overview

  • uses express
  • will create express instance if not provided
  • will piggyback on express instance if provided
  • provides heart beat service /ping
  • supports http and https
  • stand up a dozen services in a day

Just define the object literal

let ep = {
  method: method,
  path: path,
  provider: async (req,res) => { ...}
}

Or Use object constructor


let ep = new RestEndpoint(method, path, provider)

Example Hello World

GET Request at /hello


const {RestServiceFactory } = require('@stjohnd777/easyrest')

const port = 3000
const aProvider =  (req, res) =>{
    res.json({
        success:true,
        message : "Hello Easy Rest"
    });
}

let service = new RestServiceFactory(
    serviceName
    ,[ {
        method:'GET',
        path:"/hello",
        provider:aProvider
    } ]

)
service.start(port)

Path Parameters are as usual with express

  • Path parameters are part of the url itself that usually occurs after the name of the service.
  • Example /thing/:thingId

Query Parameters

  • The query string portion of a URL is the part of the URL after the question mark ?. For example: ?answer=42
  • Each key=value pair is called a query parameter.
  • If your query string has multiple query parameters, they're separated by &. For example, the below string has 2 query parameters, a and b.

?a=1&b=2

GET request to path parameters

const {RestServiceFactory } = require('@stjohnd777/easyrest')
 
let service = new RestServiceFactory(
    serviceName
    ,[ {
        method:'GET',
        path:"/widget/:prop1/:prop2",
        provider:async ()=>{
          let prop1 = req.params.props1
          let prop3 = req.params.props2
          const qps = req.query
          // do stuff ...
          res.json({ ...

          });
        }
    } ]

)
service.start(port)

Review

|HTTP method | Description | |---------------|-------------| |GET| Retrieve an existing resource.| |POST|Create a new resource.| |PUT| Update an existing resource.| |PATCH|Partially update an existing resource.| |DELETE|Delete a resource.|

Review Code Ranges

|Code |Category |-------|-------- |2xx |Successful operation |3xx |Redirection |4xx |Client error |5xx |Server error

Review Some Codes

|Code| Meaning Description |----|----------------------- |200 |OK The requested action was successful. |201 |Created A new resource was created. |202 |Accepted The request was received, but no modification has been made yet. |204 |No Content The request was successful, but the response has no content. |400 |Bad Request The request was malformed. |401 |Unauthorized The client is not authorized to perform the requested action. |404 |Not Found The requested resource was not found. |415 |Unsupported Media Type The request data format is not supported by the server. |422 |Unprocessable Entity The request data was properly formatted but contained invalid or missing data. |500 |Internal Server Error The server threw an error when processing the request.

Review API endpoint in

|HTTP |API endpoint |Description |-------|--------------------------|---- |GET |/NOUN |Get a list of NOUN. |GET |/NOUN/<noun_id>|Get a single customer. |POST |/NOUN |Create a new customer. |PUT |/NOUN/<noun_id>|Update a customer. |PATCH |/NOUN/<noun_id>|Partially update a customer. |DELETE |/NOUN/<noun_id>|Delete a customer.

Let use Task as the noun:

task = {
    id,
    assigned_to,
    name,
    description,
    due_date,
    status,
}

let epFetchTasks = {'GET', '/task/:task_id', async(req,res)=>{
    let id = req.params.task_id
    // fetch all
    let tasks = ...
    req.json {
        success: true
        tasks: tasks
    }    
}}
let epAddTask = { 'POST', '/task', async (res,res)=>{
    let body = req.body
    
}}
let epUpdateTask = { 'PUT', '/task/:task_id',async (res,res)=>{
    let body = req.body
}}
let ep = { 'PATCH', '/task/:task_id',async (res,res)=>{
    let body = req.body
    
}}
let epDeleteTask = { 'DELETE', '/task/:task_id',async (res,res)=>{
    let id = req.params.task_id
}}

const endpoints = [epFetchTasks,epAddTask,epUpdateTask,epDeleteTask]


let service = new RestServiceFactory(
    'task_services'
    ,endpoints
)
service.start(port)