Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@d1g1t/type-api

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@d1g1t/type-api

Typescript enabled API library

  • 2.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

Typescript enabled API library

Greenkeeper badge

Build Status NPM version Standard Version styled with prettier Conventional Commits

Consumption of published library:

yarn add type-api or npm install type-api

Webpack

import {RestApi} from 'type-api'

/**
 * Define rest api
 */
class PostApi extends RestApi {
    baseUrl = 'https://jsonplaceholder.typicode.com'
    endpoint = '/posts'
}

/**
 * Initialize api
 */
export const postApi = new PostApi()

// Get one by ID
try {
    const response = postApi.findById(1)

    console.log(response)
} catch (error) {
    console.error(error)
}

// Create entity
try {
    const postData =   {
        "userId": 1,
        "title": "New user",
        "body": "Some content"
    },
    const response = postApi.create(postData)

    console.log(response)
} catch (error) {
    console.error(error)
}

// Update entity
try {
    const postData =   {
        "userId": 1,
        "title": "New user",
        "body": "Some content"
    },
    const response = postApi.update(1, postData)

    console.log(response)
} catch (error) {
    console.error(error)
}

Available methods

Rest API

  • findById(id) : GET - retrieve one record as object
  • findAll() : GET - retrieve all records as list
  • findOne({name: 'some name'}) : GET - retrieve one record from list of response results
  • find({limit: 3}) : GET - retrieve records as list and generate query string from object
  • create({name: 'Some Name'}) : POST - submit object for creation
  • update(1, {name: 'Some Name'}) : PUT - submit object for update

Base API

  • get('custom')
  • post('custom', postData)
  • put('custom', putData)
  • patch('custom', patchData)

FAQs

Package last updated on 06 Mar 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc