2.0.12 • Published 2 years ago

@apiglobal/typedrequest v2.0.12

Weekly downloads
28
License
MIT
Repository
-
Last release
2 years ago

@apiglobal/typedrequest

make typed requests towards apis

Availabililty and Links

Status for master

Status CategoryStatus Badge
GitLab Pipelinespipeline status
GitLab Pipline Test Coveragecoverage report
npmnpm downloads per month
SnykKnown Vulnerabilities
TypeScript SupportTypeScript
node Supportnode
Code StyleCode Style
PackagePhobia (total standalone install weight)PackagePhobia
PackagePhobia (package size on registry)PackagePhobia
BundlePhobia (total size when bundled)BundlePhobia
Platform supportSupports Windows 10 Supports Mac OS X

Usage

Use TypeScript for best in class intellisense.

import { expect, tap } from '@pushrocks/tapbundle';
import * as smartexpress from '@pushrocks/smartexpress';

import * as typedrequest from '../ts/index';

let testServer: smartexpress.Server;
let testTypedHandler: typedrequest.TypedHandler<ITestReqRes>;

// lets define an interface
interface ITestReqRes {
  method: 'hi';
  request: {
    name: string;
  };
  response: {
    surname: string;
  };
}

tap.test('should create a typedHandler', async () => {
  // lets use the interface in a TypedHandler
  testTypedHandler = new typedrequest.TypedHandler<ITestReqRes>('hi', async (reqArg) => {
    return {
      surname: 'wow',
    };
  });
});

tap.test('should spawn a server to test with', async () => {
  testServer = new smartexpress.Server({
    cors: true,
    forceSsl: false,
    port: 3000,
  });
});

tap.test('should define a testHandler', async () => {
  const testTypedRouter = new typedrequest.TypedRouter(); // typed routers can broker typedrequests between handlers
  testTypedRouter.addTypedHandler(testTypedHandler);
  testServer.addRoute(
    '/testroute',
    new smartexpress.HandlerTypedRouter(testTypedRouter as any) // the "any" is testspecific, since smartexpress ships with its own version of typedrequest.
  );
});

tap.test('should start the server', async () => {
  await testServer.start();
});

tap.test('should fire a request', async () => {
  const typedRequest = new typedrequest.TypedRequest<ITestReqRes>(
    'http://localhost:3000/testroute',
    'hi'
  );
  const response = await typedRequest.fire({
    name: 'really',
  });
  console.log('this is the response:');
  console.log(response);
  expect(response.surname).to.equal('wow');
});

tap.test('should end the server', async () => {
  await testServer.stop();
});

tap.start();

Contribution

We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can contribute one time or contribute monthly. :)

For further information read the linked docs at the top of this readme.

MIT licensed | © Lossless GmbH | By using this npm module you agree to our privacy policy

repo-footer

2.0.11

2 years ago

2.0.12

2 years ago

2.0.9

2 years ago

2.0.10

2 years ago

2.0.5

2 years ago

2.0.7

2 years ago

2.0.6

2 years ago

2.0.8

2 years ago

2.0.3

2 years ago

2.0.2

2 years ago

1.0.66

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.0.67

2 years ago

1.0.62

3 years ago

1.0.65

3 years ago

1.0.64

3 years ago

1.0.63

3 years ago

1.0.58

3 years ago

1.0.57

3 years ago

1.0.56

3 years ago

1.0.55

3 years ago

1.0.54

4 years ago

1.0.53

4 years ago

1.0.50

4 years ago

1.0.49

4 years ago

1.0.48

4 years ago

1.0.43

4 years ago

1.0.42

4 years ago

1.0.41

4 years ago

1.0.40

4 years ago

1.0.39

4 years ago

1.0.38

4 years ago

1.0.37

4 years ago

1.0.36

4 years ago

1.0.35

4 years ago

1.0.34

4 years ago

1.0.32

4 years ago

1.0.31

4 years ago

1.0.30

4 years ago

1.0.29

4 years ago

1.0.28

4 years ago

1.0.27

4 years ago

1.0.24

5 years ago

1.0.18

5 years ago

1.0.17

5 years ago

1.0.16

5 years ago

1.0.15

5 years ago

1.0.14

5 years ago

1.0.13

5 years ago

1.0.12

5 years ago

1.0.11

5 years ago

1.0.3

5 years ago