Git Product home page Git Product logo

pay-request's Introduction

Pay request ๐ŸŒ

Build Status Known Vulnerabilities

Npm latest version

Simple HTTP client for internal GOV.UK Pay services.

Provides a consistent request language across disparate backend route styles.

import { Ledger } from '@govuk-pay/request'

const payments = await Ledger.payments.list()

Usage

Getting started

Pay request will check the environment for base URLs for each internal service client. The simplest way to get up and running is to set these for required services.

CONNECTOR_URL, ADMINUSERS_URL, PUBLICAUTH_URL, LEDGER_URL, PRODUCTS_URL

For advanced setup, read more about configuring the library.

Installation

Pay request builds on the axios HTTP client. Axios is not bundled and should be installed as a peer dependency alongside Pay request.

npm i axios @govuk-pay/request

Request language

retrieve(id)

Get one entity details.

const payments = await Ledger.payments.retrieve('ofd7t9jbsq844rlv3agthdu9am')

list()

List all entities, these resources usually support pagination and filters.

const payments = await Ledger.payments.list({
    card_brand: CardBrand.Visa
})

update(id, params)

Update an entity with supported request params.

await AdminUsers.users.update('user-id', {
    disabled: false
})

delete(id)

Delete entity.

await PublicAuth.tokens.delete({ token_link: 'token-id' })

Configuration

Pay request exposes a top level config() method. By default the library will use process.env to check for URLs that map to clients.

These URLs can also overridden with the config() method.

import { config } from '@govuk-pay/request'

config({
    CONNECTOR_URL: 'https://custom.digital/'
})

Pay request also supports hooks into the request lifecycle for logging and custom headers.

config(process.env, {
    failureResponse: (context) => { console.log(`Request from ${context.service} failed with ${context.code}`) },
    successResponse: (context) => { console.log(`Request from ${context.service} returned in ${context.responseTime}`) },
    transformRequestAddHeaders: () => ({
        'x-request-id': 'correlation-id'
    })
})

Service data structure

Type definitions are provided for all requests, responses and entities served by backend resources.

Experimental

OpenAPI is used to generate type shape structures for each of the clients based on .json specification for that service.

For any internal service that doesn't have full annotations for OpenAPI there are services/${client}/types.ts polyfill definitions to provide a uniform developer experience.

pay-request's People

Contributors

sfount avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.