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

requestor-api

v1.0.8

Published

> Http Generic Type Callback

Downloads

4

Readme

Http Generic Type Callback

Installation

$ npm install --save requestor-api   

Usage

server

Server response object has to extend the followng models:

On Success

  success:boolean

On Failure

  success: boolean,
  messages: string[]
  errorCode: number

client

Implement OnRequestorCallback

   export default class ButtonComponent extends Vue implements  OnRequestorCallback{...}

Will implements 3 methods

    
    onProgress(requstName?: string): void {
        // progress, by default requestName is empty
    }

    onSuccess<T>(data?: T, requstName?: string, message?: string): void;
    onSuccess<T>(data?: T[], requstName?: string, message?: string): void;
    
    onSuccess(data?: any, requstName?: any, message?: any) {
        // success return object or array
    }
    
    onError(message: string, code: number, requstName?: string): void {
        // error with message and code
    }

Headers

    
    let header: Header = new Header()
    
    header.append("Authorization","Bearer xxx.xxx")
          .append("UserToken","some-token-for-user")
          ....
          .append("More","headers-parameters");

Url Parameters

Query String (over url)

    let qs = new QueryString()
               .append("token", "xxx.xxx.xxx")
               .append("type", "jwt")

will generate url like -> www.some-url.com/?token=xxx.xxx.xxx&type=jwt

Routing Rule (over url)

 let rr = new RoutingRule()
             .append("user")
             .append("xxx.xxx.xxx")

will generate url like -> www.some-url.com/user/xxx.xxx.xxx

Requests

Http Get, Post, Put, Delete

In all requests you shuold call commit

commit<T>(baseUrl: string, apiUrl: string, callback: OnRequestorCallback, requestName?: string): void;

Get

// Without url parameters & no request name
    new HttpGet().commit(baseUrl, apiUrl, requestorCallback);


//  with Header and Query String
    new HttpGet().setHeader(header)
                 .setQueryString(qs)
                 .commit(baseUrl, apiUrl, requestorCallback, name);

// With Routing Parameters & Header
    new HttpGet().setHeader(header)
                 .setRoutingRule(rr)
                 .commit(baseUrl, apiUrl, requestorCallback, name);

Post


//Example for POCO class
    class User{
        userId:number;
        name:string;
        email:string;
    }

    let user = new User();
        user.userId = 1;
        user.name = "jhon doe";
        user.email = "[email protected]";

    new HttpPost().setHeader(header)
                .setBody(user)
                .commit<User>(baseUrl,apiUrl,this,'usersData');

    // With Url Parameters
    new HttpPost().setHeader(header)
                .setQueryString(qs)
                .setBody(user)
                .commit<User>(baseUrl,apiUrl,this,'dataWithBody');

    // Or
    new HttpPost().setHeader(header)
                .setRoutingRule(rr)
                .setBody(user)
                .commit<User>(baseUrl,apiUrl,this,'dataWithBodyAndRR');

Button Login Example based on requestor with Http Post Request

import Vue from 'vue';
import Component from 'vue-class-component';
import { OnRequestorCallback, HttpGet, Header, HttpPost, RoutingRule, QueryString } from 'requestor';


//Create Your POCO class
export class User {
  managingCompanyId: number;
  idNumber: string;
  password: string;
}


@Component({})
export default class LoginButton extends Vue implements OnRequestorCallback {

  private header: Header = new Header();

  constructor() {
    super();
    this.header.append("Authorization", "some-auth");
  }

  //Login event
  onLogin() {

    // Create routeing params
    let rr: RoutingRule = new RoutingRule()
      .append("user")

    // Create your new User
    let user: User = new User();
    user.managingCompanyId = 1;
    user.fname = "mad"
    user.lname = "max"
    user.idNumber = "123";
    user.password = "22445445";

    //Call to http Post request
    new HttpPost()
      .setHeader(this.header)
      .setRoutingRule(rr)
      .setBody(user)
      .commit(baseUrl,api, this, "Valhalla")


  }

  onProgress(requstName?: string | undefined): void {

  }

  onSuccess<User>(data?: User | undefined, requstName?: string | undefined, message?: string | undefined): void;
  onSuccess<User>(data?: User[] | undefined, requstName?: string | undefined, message?: string | undefined): void;
  onSuccess(data?: any, requstName?: any, message?: any) {

    /*
      Return Serilized User Object
    */

  }

  onError(message: string, code: number, requstName?: string | undefined): void {
    /*
      Return error with status code and message as expected format (success/failure) explain above
    */
  }

  onProgressFinished(success: boolean): void {
    
  }

}

Delete // Todo

License

MIT

daniel gi