Socket
Book a DemoInstallSign in
Socket

@api-def/provider-http

Package Overview
Dependencies
Maintainers
0
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@api-def/provider-http

latest
npmnpm
Version
0.2.2
Version published
Maintainers
0
Created
Source

@api-def/provider-http

This package implements HTTP API provider for @api-def/core infrastructure.

API Definition

Basic

Example

In order to use the HTTP provider you will first need to create an API:

const api = createHttpApi({
  baseUrl: 'https://my-api.com',
})

@api-def doesn't enforce any way the endpoints should be saved. For this example we will use an object to compose endpoints together

const news = {
  get: api.defineJsonEndpoint<
    void,
    {
      data: object[]
    }
  >({
    method: 'GET',
    url: '/news',
    output: 'naive',
  }),
  create: api.defineJsonEndpoint<
    {
      title: string
      content: string
    },
    {
      data: object
    }
  >({
    method: 'POST',
    url: '/news',
    output: 'naive',
  }),
}

Then in order to execute the endpoints:

news.create.execute().then((value) => console.log(value))
news.get.execute().then((value) => console.log(value))

Now the logic of HTTP request is abstracted away! Cheers!

Authentication

Documentation coming soon...

Going further than JSON requests

Documentation coming soon...

License

MIT

Copyright (c) 2024-present, Artem Tarasenko

FAQs

Package last updated on 25 Nov 2024

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