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

yas-http

v1.1.11

Published

Support to send http(s) requests, API document and Http(s) mock server

Downloads

32

Readme

yas-http

Support to send http(s) requests, API document and Http(s) mock server

It's an extension for yaml-scene

Features:

  • Create testcases to test APIs
  • Send http(s) requests
  • Create a mock API server
    • Server static file
    • Support upload file then save to server
    • Server RESTFul API data
    • Create APIs which auto handle CRUD data
    • Build router for yourself by code
  • Generate API document

Sharing

  1. Create dynamic mock API Server
  2. Download youtube mp3 file
  3. Quick upload file to get a share link

Details document

Wiki Pages

Prerequisite

Installation

  yas add yas-http        # npm install -g yas-http OR yard global add yas-http

Example

Examples scenario files

HTTP Client Request

Send a http request to a server

Send GET request

- yas-http/Get:
    url: http://localhost:3000/posts

Send POST request

- yas-http/Post:
    url: http://localhost:3000/posts
    body:
      id: 2
      title: title 2
      author: typicode 2

Send PUT request

- yas-http/Put:
    url: http://localhost:3000/posts/:id
    params:
      id: 2
    body:
      id: 2
      title: title 2 updated
      author: typicode 2 updated

Send PATCH request

- yas-http/Patch:
    url: http://localhost:3000/posts/:id
    params:
      id: 2
    body:
      id: 2
      title: title 2 updated
      author: typicode 2 updated

Send DELETE request

- yas-http/Delete:
    url: http://localhost:3000/posts/:id
    params:
      id: 2

Send HEAD request

- yas-http/Head:
    url: http://localhost:3000/posts/:id
    params:
      id: 2

Send CUSTOM request

- yas-http/Api:
    method: CONNECT
    url: http://localhost:3000/posts

Mock API Server

Create mock API Server without code

Server static file

- yas-http/Server:
    host: 0.0.0.0                               # Server host
    port: 8000                                  # Server port
    routers:                                    # Defined routes
      - serveIn: 
          - ./assets                            # All of files in list will be served after request to

Support upload file then save to server

- yas-http/Server:
    host: 0.0.0.0                               # Server host
    port: 8000                                  # Server port
    routers:                                    # Defined routes
      - path: /upload                           # Upload path. Default method is POST
        method: POST                            # Request method (POST, PUT, PATCH, DELETE, HEAD)
                                                # - Default method is POST
        uploadTo: ./uploadDir                   # Directory includes uploading files

Server RESTFul API data

- yas-http/Server:
    host: 0.0.0.0                               # Server host
    port: 8000                                  # Server port
    routers:                                    # Defined routes
      - method: GET                             # Request method (GET, POST, PUT, PATCH, DELETE, HEAD) (Default: GET)
        path: /posts/:id                        # Request path
        response:                               # Response data
          status: 200                           # - Response status
          statusMessage: OK                     # - Response status message
          headers:                              # - Response headers
            server: nginx
          data: [                               # - Response data. 
            {                                   #   - Use some variables to replace value to response
              "id": ${+params.id},              # params:  Request params (/:id)
              "title": "title 1",               # headers: Request headers
              "author": "thanh"                 # query:   Request querystring (?name=thanh)
              "des": "des 1",                   # body:    Request body
            }                                   # request: Request
          ]                                     # ctx:     Context

Create APIs which auto handle CRUD data

- yas-http/Server:
    host: 0.0.0.0                               # Server host
    port: 8000                                  # Server port
    routers:                                    # Defined routes
      - path: '/:model'                         # Use this pattern to use with dynamic model name
        CRUD: true                              # Auto create full RESTful API
        dbFile: ./db.json                       # Store data to file. This make the next time, when server up will load data from the file.
                                                # - Empty then it's stateless
        clean: true                             # Clean db before server up
                                                # - GET    /model            : Return list models
                                                # - GET    /model/:id        : Return model details by id
                                                # - POST   /model            : Create a new model
                                                # - PUT    /model/:id        : Replace entity of post to new model
                                                # - PATCH  /model/:id        : Only update some properties of model
                                                # - DELETE /model/:id        : Delete a model by id
        initData: {                             # Init data for dynamic model name (/:model). 
                                                # - Only init data when 
                                                #   + Db file not existed
                                                #   + OR set "cleaned"
                                                #   + OR not set dbFile
          posts: [{                             # When you request /posts, it returns the value
            "id": 1,
            "label": "label 01"
          }],
          users: [{                             # When you request /users, it returns the value
            "id": 1,
            "label": "user 01"
          }]  
        }

Build router for yourself by code

- yas-http/Server:
    host: 0.0.0.0                               # Server host
    port: 8000                                  # Server port
    routers:                                    # Defined routes
      - method: GET                             # Request method (GET, POST, PUT, PATCH, DELETE, HEAD) (Default: GET)
        path: /posts/:id                        # Request path
        handler: !function |                    # Handle code which handle request and response data
          (globalVars) {                                      
            // this.params: Request params
            // this.headers: Request headers
            // this.query: Request query string
            // this.body: Request body
            // this.request: Request
            // this.ctx: Context (koajs)

            const merge = require('lodash.merge')   
            return merge({                          
              params: this.params.id,                    
              name: this.query.name                      
            }, {                                    
              id: 1
            })
          }                

Document to markdown

- yas-http/Doc/MD:
    title: Post service
    description: Demo CRUD API to generate to markdown document
    signature: "[Doan Thuan Thanh](mailto:[email protected])"
    outFile: ./ApiMD.md

Add doc in the yas-http/Get... to export to document

- yas-http/Get:
    doc: true
    ...
- yas-http/Delete:
    doc: 
      tags: [POST]
    ...

API request summary

Collect information of http(s) calls

yas-http/Summary:
  title: Testing result