Skip to content

Commit

Permalink
feat: Adjust JSON stringification for improved readability in respons…
Browse files Browse the repository at this point in the history
…e display components
  • Loading branch information
SivaramPg committed Dec 16, 2024
1 parent ab8ee3a commit 25023bc
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/app/[category]/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export default async function Page({
<ApiEndpointElement text={data.url} />
<RequestDisplayElement slug={`/${category}/${slug}`} />
<ResponseDisplayElement>
{JSON.stringify(data, null, 8)}
{JSON.stringify(data, null, 2)}
</ResponseDisplayElement>
</main>
)
Expand Down
2 changes: 1 addition & 1 deletion src/app/[category]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export default async function Page({
<ApiEndpointElement text={`https://swapi.info/api/${category}`} />
<RequestDisplayElement slug={`/${category}`} />
<ResponseDisplayElement>
{JSON.stringify(data, null, 8)}
{JSON.stringify(data, null, 2)}
</ResponseDisplayElement>
<div className={cn("w-full max-w-screen-lg flex flex-col gap-2")}>
<h4 className="text-lg font-bold md:text-xl lg:text-2xl opacity-70">
Expand Down
2 changes: 1 addition & 1 deletion src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default async function Home() {
<div className="container flex flex-col items-center justify-center gap-8 px-4 mx-auto">
<RequestDisplayElement slug={"/"} />
<ResponseDisplayElement>
{JSON.stringify(data, null, 8)}
{JSON.stringify(data, null, 4)}
</ResponseDisplayElement>
<div className={clsx("w-full max-w-screen-lg flex flex-col gap-2")}>
<h4 className="text-lg font-bold md:text-xl lg:text-2xl opacity-70">
Expand Down
6 changes: 3 additions & 3 deletions src/components/RequestDisplayElement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default RequestDisplayElement

function getRequest(slug: string) {
return `fetch("https://swapi.info/api${slug}")
.then((res) => res.json()) // Parse the JSON content from the API to be consumed
.then((json) => console.log(json)) // Log the JSON response to your console
.catch((error) => console.error(error)) // Log the API error (if any) to your console`
.then((res) => res.json()) // Parse the JSON content from the API to be consumed
.then((json) => console.log(json)) // Log the JSON response to your console
.catch((error) => console.error(error)) // Log the API error (if any) to your console`
}

0 comments on commit 25023bc

Please sign in to comment.