Skip to content

Commit

Permalink
fix: update http client code examples (#335)
Browse files Browse the repository at this point in the history
* fix: update http client code examples

* fix: update missing example
  • Loading branch information
kevinperaza committed Feb 15, 2024
1 parent b4907ad commit 6aeafa0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
24 changes: 18 additions & 6 deletions docs/sdks/web/javascript/services.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,9 @@ Element values can be used in a request to a third-party API using our HTTP clie
The example below shows how to use the HTTP client service to make a POST request to a third-party API with an element in the payload.

```javascript showLineNumbers title="Invoking HTTP Client Service w/ POST"
BasisTheory.post(
const bt = await new BasisTheory().init("<API_KEY>", { elements: true });

bt.client.post(
"https://www.api.thirdpartydomain.com/resources",
{
sensitiveData: sensitiveDataElement,
Expand Down Expand Up @@ -343,7 +345,9 @@ BasisTheory.post(
The example below shows how to use the HTTP client service to make a PUT request to a third-party API with an element in the payload.

```javascript showLineNumbers title="Invoking HTTP Client Service w/ PUT"
BasisTheory.put(
const bt = await new BasisTheory().init("<API_KEY>", { elements: true });

bt.client.put(
"https://www.api.thirdpartydomain.com/resources/id",
{
sensitiveData: sensitiveDataElement,
Expand Down Expand Up @@ -372,7 +376,9 @@ BasisTheory.put(
The example below shows how to use the HTTP client service to make a PATCH request to a third-party API with an element in the payload.

```javascript showLineNumbers title="Invoking HTTP Client Service w/ PATCH"
BasisTheory.patch(
const bt = await new BasisTheory().init("<API_KEY>", { elements: true });

bt.client.patch(
"https://www.api.thirdpartydomain.com/resources/id",
{
sensitiveData: sensitiveDataElement,
Expand Down Expand Up @@ -401,7 +407,9 @@ BasisTheory.patch(
The example below shows how to use the HTTP client service to make a GET request to a third-party API.

```javascript showLineNumbers title="Invoking HTTP Client Service w/ GET"
BasisTheory.get("https://www.api.thirdpartydomain.com/resources/id", {
const bt = await new BasisTheory().init("<API_KEY>", { elements: true });

bt.client.get("https://www.api.thirdpartydomain.com/resources/id", {
headers: {
Accept: "application/json",
},
Expand All @@ -417,7 +425,9 @@ BasisTheory.get("https://www.api.thirdpartydomain.com/resources/id", {
The example below shows how to use the HTTP client service to make a DELETE request to a third-party API.

```javascript showLineNumbers title="Invoking HTTP Client Service w/ DELETE"
BasisTheory.delete("https://www.api.thirdpartydomain.com/resources/id", {
const bt = await new BasisTheory().init("<API_KEY>", { elements: true });

bt.client.delete("https://www.api.thirdpartydomain.com/resources/id", {
headers: {
Accept: "application/json",
},
Expand Down Expand Up @@ -464,7 +474,9 @@ HTTP client services could throw an error based on client-side validations or if
```javascript showLineNumbers title="Handling services errors"
import { HttpClientError, BasisTheoryValidationError } from "@basis-theory/basis-theory-js/common";

BasisTheory.post({
const bt = await new BasisTheory().init("<API_KEY>", { elements: true });

bt.client.post({
sensitiveData: textElement,
}).catch((error) => {
if (error instanceof BasisTheoryValidationError) {
Expand Down
10 changes: 5 additions & 5 deletions docs/sdks/web/react/services.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ const MyForm = () => {
const cardVerificationCode = cardVerificationCodeRef.current;

try {
const response = await bt.post('https://www.api.thirdpartydomain.com/resources', {
const response = await bt.client.post('https://www.api.thirdpartydomain.com/resources', {
number: cardNumber,
expiration_month: cardExpirationDate.month(),
expiration_year: cardExpirationDate.year(),
Expand Down Expand Up @@ -572,7 +572,7 @@ const MyForm = () => {
const cardVerificationCode = cardVerificationCodeRef.current;

try {
const response = await bt.put('https://www.api.thirdpartydomain.com/resources/id', {
const response = await bt.client.put('https://www.api.thirdpartydomain.com/resources/id', {
number: cardNumber,
expiration_month: cardExpirationDate.month(),
expiration_year: cardExpirationDate.year(),
Expand Down Expand Up @@ -632,7 +632,7 @@ const MyForm = () => {
const cardVerificationCode = cardVerificationCodeRef.current;

try {
const response = await bt.patch('https://www.api.thirdpartydomain.com/resources/id', {
const response = await bt.client.patch('https://www.api.thirdpartydomain.com/resources/id', {
number: cardNumber,
expiration_month: cardExpirationDate.month(),
expiration_year: cardExpirationDate.year(),
Expand Down Expand Up @@ -684,7 +684,7 @@ const MyForm = () => {

const submit = async () => {
try {
const response = await bt.get('https://www.api.thirdpartydomain.com/resources/id', {
const response = await bt.client.get('https://www.api.thirdpartydomain.com/resources/id', {
headers: {
'Accept': 'application/json',
},
Expand Down Expand Up @@ -727,7 +727,7 @@ const MyForm = () => {

const submit = async () => {
try {
const response = await bt.delete('https://www.api.thirdpartydomain.com/resources/id', {
const response = await bt.client.delete('https://www.api.thirdpartydomain.com/resources/id', {
headers: {
'Accept': 'application/json',
},
Expand Down

0 comments on commit 6aeafa0

Please sign in to comment.