url-shortening-api-master Tailwind Templates

Url Shortening Api Master

This is a landing page for a company called Shortly that provides a URL shortening API. The page is fully responsive and built with React. The page is styled with Tailwind. The page is deployed on Netlify.

Frontend Mentor - Shortly URL shortening API Challenge solution

This is a solution to the Shortly URL shortening API Challenge challenge on Frontend Mentor. Frontend Mentor challenges help you improve your coding skills by building realistic projects.

Table of contents

Overview

This is a landing page for a company called Shortly that provides a URL shortening API. The page is fully responsive and built with React. The page is styled with Tailwind. The page is deployed on Netlify.

The challenge

Users should be able to:

  • View the optimal layout for the site depending on their device's screen size
  • Shorten any valid URL
  • See a list of their shortened links, even after refreshing the browser
  • Copy the shortened link to their clipboard in a single click
  • Receive an error message when the form is submitted if:
    • The input field is empty

Screenshot

Desktop

Desktop Desktop-Active

Mobile

Mobile Mobile-Active Mobile-menu

My process

Built with

Note: These are just examples. Delete this note and replace the list above with your own choices

What I learned

I learned how to use React-Query to fetch data from an API.

import { useQuery } from '@tanstack/react-query';

function useShortenLink(longLink) {
  return useQuery(
    ['linkData', longLink],
    () => fetch('/.netlify/functions/shortenLink', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({ url: longLink }),
    }).then((res) => res.json()),
    {
      enabled: !!longLink, // only run the query if longLink is defined
      staleTime: Infinity, // prevent automatic refetching when the data is stale
      cacheTime: Infinity, // keep the data in the cache indefinitely
    }
  );
}

export default useShortenLink;

Continued development

I want to improve the styling of the page and refine it a bit further, but since I am on some time constraints due to other obligations, I wasn't able to do so at this point.

Useful resources

  • Tailwind Docs - It's always nice searching up the tailwind docs because its so easy to use and find what you need
  • Tanstack React Query Docs - My first time using React Query so this was very nice to go through and learn how to use it

Author

Top categories

tailwind logo

Need a Tailwind website built?

Hire a professional TailwindCSS developer today.
Loading Svelte Themes