![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
@carforyou/api-client
Advanced tools
npm install @carforyou/api-client
Initialize the API client:
import { ApiClient } from "@carforyou/api-client"
ApiClient.configure(<your_configuration_object>)
Import the fetchXYZ
call you need and use in your code:
import { fetchReferenceData } from "@carforyou/api-client"
fetchReferenceData()
Option Name | Meaning |
---|---|
host | URL to the API gateway |
debug | Set to true to console.log requests and API responses. |
You can pass a custom host
with the API calls options object.
Backend offers stub APIs for each service, which you can use:
import { fetchListings } from "@carforyou/api-client"
fetchListings({ host: "https://inventory-search-service-stub.dev.carforyou.ch" })
If you want to provide your own mock data, serve a mock json file locally with json-server.
import { fetchListings } from "@carforyou/api-client"
fetchListings({ host: "http://localhost:3001" })
Requests that need authorization, need to pass a valid JWT to authenticate the user on the requested resource.
To authenticate a request, simply pass the isAuthorizedRequest
option to the request helper (fetch/post/put/delete-Data) and the api client will add the Authorization
header. For server side requests, don't forget to pass the options down to the helper function so the consumer can pass the accessToken
when invoking the request.
Note: If one forgets to add the isAuthorizedRequest
option, the access token will not be set as a header. On the consumer side, if the access token is not passed, the api client will throw an error.
Pass the access token as a request option to the api call dummyFetchCall(data, {accessToken: JWT})
The consumer is responsible to ensure a valid token is passed to the request. The api client will pass the provided token as an Authorization
header to the api call.
Also accompanying modes and param types, as well as default values, are exported.
fetchFrameNumberTypes
fetchFrameNumberOptions
fetchProductionYearByFrameNumber
To be able to mock api calls in tests you need to:
import { fetchListing } from "@carforyou/api-client"
jest.mock("@carforyou/api-client", () => ({
// Add this if you want to have access to other exported methods
...jest.requireActual("@carforyou/api-client"),
fetchListing: jest.fn(),
}))
(fetchListing as jest.Mock).mockReturnValue(`<your mocked data>`)
typecasting is only needed in TypeScript projectsexpect(fetchListing).toHaveBeenCalled()
Be aware that this creates a global mock in your tests. You'd need to clear mock state in beforeEach
:
(fetchListing as jest.Mock).mockClear()
Following factories are exported:
TypeFactory
SearchTypeFactory
OptionsFactory
ListingFactory
SearchListingFactory
EmptyListing
- builds a listing without any valuesListingFromType
- initializes an empty listing with values from a typeSearchMessageLeadFactory
- builds lead email listingSearchCallLeadFactory
- builds lead call listingnpm run build
You can link your local npm package to integrate it with any local project:
cd carforyou-api-client-pkg
npm run build
cd carforyou-listings-web
npm link ../carforyou-api-client-pkg
New versions are released on the ci using semantic-release as soon as you merge into master. Please make sure your merge commit message adheres to the corresponding conventions.
FAQs
Api client to connect with our APIs
The npm package @carforyou/api-client receives a total of 273 weekly downloads. As such, @carforyou/api-client popularity was classified as not popular.
We found that @carforyou/api-client demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
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.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.