Gathering detailed insights and metrics for @justeat/f-http
Gathering detailed insights and metrics for @justeat/f-http
Gathering detailed insights and metrics for @justeat/f-http
Gathering detailed insights and metrics for @justeat/f-http
npm install @justeat/f-http
Typescript
Module System
Min. Node Version
Node Version
NPM Version
69.2
Supply Chain
98.6
Quality
84.5
Maintenance
100
Vulnerability
100
License
core-analytics@1.21.0
Published on 11 Jul 2023
f-header@v10.15.0
Published on 26 Jun 2023
f-registration@3.8.0
Published on 28 Oct 2022
f-registration@3.7.2
Published on 21 Oct 2022
f-error-message@2.3.0
Published on 03 Oct 2022
f-header@10.7.0
Published on 13 Sept 2022
JavaScript (73.55%)
Vue (17.7%)
SCSS (5.65%)
MDX (2.88%)
HTML (0.19%)
CSS (0.01%)
Handlebars (0.01%)
Total Downloads
13,265
Last Day
1
Last Week
1
Last Month
5
Last Year
2,210
16 Stars
1,971 Commits
38 Forks
32 Watching
271 Branches
78 Contributors
Minified
Minified + Gzipped
Latest Version
1.1.1
Package Id
@justeat/f-http@1.1.1
Unpacked Size
407.12 kB
Size
110.07 kB
File Count
8
NPM Version
lerna/3.22.1/node@v20.12.2+x64 (linux)
Node Version
20.12.2
Publised On
29 Apr 2024
Cumulative downloads
Total Downloads
Last day
0%
1
Compared to previous day
Last week
-75%
1
Compared to previous week
Last month
-90.7%
5
Compared to previous month
Last year
167.6%
2,210
Compared to previous year
2
Javascript HTTP client for interacting with restful services
This package exposes methods for interacting with restful services, it may abstract any number of popular NPM packages which provide the ability to perform GET, PUT, POST, PATH, DELETE requests; while also adding some additional benefits.
Install the module using npm or Yarn
1yarn add @justeat/f-http
Ideally the package should be initialised by your website and the httpClient placed in context or a prototype, rather than initialising it in each individual component or every time you make a request.
httpClient
1import httpModule from '@justeat/f-http'; 2 3const options = { // Options are described later 4 baseUrl: 'https://jsonplaceholder.typicode.com' 5}; 6 7// Optional: Implement wrapper using cookie tech you have available 8// Enables conversation ID to be automatically provided with requests 9const getCookieFunction = cookieName => app.$cookies.get(cookieName); 10 11const httpClient = new httpModule.CreateClient(options, getCookieFunction); 12 13// WHEN: Using a Nuxt Plugin 14inject('http', httpClient); 15 16// WHEN: Using Vue CLI 17Vue.prototype.$http = httpClient;
Recommended: Using the prototype (Vue) or context (Nuxt). You can access $http in components, or anywhere the context is available including vuex modules.
1export default { 2 data () { 3 return { 4 apiResult: null 5 } 6 }, 7 async mounted () { 8 this.apiResult = await this.$http.get('/todos/1'); 9 } 10}
If you would rather create the HTTPClient when you use it, that's fine too; it just means it can't be reused as easily and you will need to filter the configuration options down to the component.
1export default { 2 async mounted () { 3 const configuration = { // Options are described later 4 baseUrl: 'https://jsonplaceholder.typicode.com' 5 }; 6 7 const httpClient = new httpModule.CreateClient(configuration); 8 9 const result = await httpClient.get('/todos/1'); 10 } 11}
You can globally set the authorisation token so that all requests provide it
1// Some event happened that means we now have a token 2export default { 3 mounted () { 4 this.$http.setAuthorisationToken('my token'); 5 } 6}
Because $http exists in context, it should be really easy to mock it in any way you want. Check out the example below
1const wrapper = mount(MyComponent, { 2 mocks: { 3 $http: { 4 get: jest.fn() 5 } 6 } 7});
The module exposes a way to create a MockClient, so you can mock the underlying API with pre-configured responses.
1import { httpVerbs, MockFactory, CreateClient } from '@justeat/f-http'; 2 3const mockFactory = new MockFactory(); 4const httpClient = new CreateClient(); 5 6const wrapper = mount(MyComponent, { 7 mocks: { 8 $http: httpClient 9 } 10}); 11 12// Reset all previously configured responses 13mockFactory.reset(); 14 15// Setup a fake response 16mockFactory.setupMockResponse(httpVerbs.POST, '/URL', REQUEST_DATA, 201);
None of these parameters are required, but using them enables you to customise your http client
Option | Description | Type | Default |
---|---|---|---|
options | An object containing options you wish to override (see below) | object | {} |
getCookieFunction | Wrapper function providing ability to read cookies | function | null |
statisticsClient | Instance of f-statistics to capture dependency timings | object | null |
All options are optional, you don't need to specify any overrides if you are happy with the default values
Option | Description | Type | Default |
---|---|---|---|
baseUrl | Ensure all requests from this client use a relative url | string | '' |
timeout | How long each request takes to timeout | number | 10000 |
errorCallback | A function you can use to globally handle errors (accepts error object) | function | null |
contentType | Specify a value for the content type header | string | 'application/json' |
These are all of the methods exposed by the httpClient
Method | Description | Parameters |
---|---|---|
get | GET a resource | resource URL [string], headers [array] |
post | POST a resource | resource URL [string], body [object], headers [array] |
put | PUT a resource | resource URL [string], body [object], headers [array] |
patch | PATCH a resource | resource URL [string], body [object], headers [array] |
delete | DELETE a resource | resource URL [string], headers [array] |
setAuthorisationToken | Set the authorisation token for all requests | authorisationToken [string] |
readConfiguration | Returns the provided options | None |
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
Found 27/30 approved changesets -- score normalized to 9
Reason
license file detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
64 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-12-23
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More