Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Lahirutech/2ea47de063359de8c03555ed13b523e7 to your computer and use it in GitHub Desktop.
Save Lahirutech/2ea47de063359de8c03555ed13b523e7 to your computer and use it in GitHub Desktop.
import { useState } from 'react'
import './App.css'
export default function App() {
const [url, setUrl] = useState("")
const [shurl, setShUrl] = useState("")
// https://api-ssl.bitly.com/v4/shorten
const postUrl = () => {
fetch("https://api-ssl.bitly.com/v4/shorten", {
method: "post",
headers: {
"Content-Type": "application/json",
"Authorization": 'Bearer ' + import.meta.env.VITE_BITLY
}, body: JSON.stringify({ long_url: url })
}).then(res => res.json()).then(data => {
console.log(data)
setShUrl(data.link)
})
}
const handleSubmit = (e: React.MouseEvent<HTMLButtonElement>) => {
e.preventDefault()
console.log("called")
postUrl()
}
return (
<main>
SHort URL:{shurl} <br />
Input Url: <input type="te
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment