2.0.0-beta.1 • Published 5 years ago

type-api v2.0.0-beta.1

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

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)
2.0.0-beta.1

5 years ago

2.0.0-beta.0

5 years ago

1.2.0

5 years ago

1.2.0-3

5 years ago

1.2.0-2

5 years ago

1.1.3-beta.1

5 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago

1.0.0-beta.1

6 years ago

1.0.0-beta.0

6 years ago

0.1.0-beta.8

6 years ago

0.1.0-beta.7

6 years ago

0.1.0-beta.6

6 years ago

0.1.0-beta.5

6 years ago

0.1.0-beta.4

7 years ago

0.1.0-beta.3

7 years ago

0.1.0-beta.2

7 years ago

0.1.0-beta.1

7 years ago

0.1.0-beta.0

7 years ago

0.0.2-beta.5

7 years ago

0.0.2-beta.4

7 years ago

0.0.2-beta.3

7 years ago

0.0.2-beta.2

7 years ago

0.0.2-beta.1

7 years ago

0.0.2-beta.0

7 years ago

0.0.2-alpha.0

7 years ago

0.0.1

7 years ago