Back to APIs list

Hacker News API examples & templates

Use these vals as a playground to view and fork Hacker News API examples and templates on Val Town. Run any example below or find templates that can be used as a pre-built solution.
stevekrouse avatar
stevekrouse
cnnEx
Script
An interactive, runnable TypeScript val by stevekrouse
0
dvsj avatar
dvsj
subscribeToNewsletter
HTTP
Add an email entry option to your static website/blog. Easy peasy. 🚀 PoV: You just hacked together a portfolio website or launched a blog as a static website. Some people who visit might be interested in hearing more from you. ❤️ But you don't want to get lost building your backend, API, DB or fancy apps like SubstandardStack or MailMachineGun for people to sign up to your newsletter. 😩 All you want is a simple input box on your website - when someone types their email , username or social link in and submits it, you want to be notified. psst...do you want another one that uses the DB instead of email so you can look up all entries at once? Let me know and I'll get cooking! Quickstart Call the val URL with data in the query param userContact . That's it! // Format `https://<val_url>?userContact=<mandatory_primary_contact>` // Examples `https://dvsj-subscribeToNewsletter.web.val.run?userContact=dav.is@zohomail.in` `https://dvsj-subscribeToNewsletter.web.val.run?userContact=CatalanCabbage` Bonus Have extra data apart from email? Pass any encoded data in the queryParam userData , will be included in the email. It's optional. // Format `https://<val_url>?userContact=<mandatory_primary_contact>&userData=<optional_any_data>` //Examples `https://dvsj-subscribeToNewsletter.web.val.run?userContact=dav.is@zohomail.in&userData={"time": "2/2/1969", "twitter": "https://twitter.com/dvsj_in"}` // Note: All values should be URL encoded. Example: let userData = {"time": "2/2/1969", "twitter": "https://twitter.com/dvsj_in"} let encodedUserData = encodeURIComponent(userData) //This should go in the query param Want bot protection? Add a simple question to your website, like "okay, so what's one minus one?" . In the val, set isBotProtectionOn = true and botProtectionAnswer="0" . When you call the val, include the encoded user's answer to the bot question as botProtection query param. Answer will be compared with botProtectionAnswer ; if the answer is wrong, the request is rejected. // Format `https://<val_url>?userContact=<mandatory_primary_contact>&userData=<optional_any_data>&botProtection=<answer>` //Examples `https://dvsj-subscribeToNewsletter.web.val.run?userContact=dav.is@zohomail.in&botProtection=123` Add it to your website Want to add it to your site but get a headstart coding it? Use this ChatGPT prompt to get code for your website! I'm building a simple form submission component. It should a submit button and these 2 input boxes: 1. "userContact" to get the user's email (mandatory) 2. "userData" to get a custom message from the user (optional) On clicking the submit button: 1. Both input values should be encoded using "encodeURIComponent" 2. A GET URL should be built in this format with query params. Include userData query param only if input is not null or empty. `https://dvsj-subscribeToNewsletter.web.val.run?userContact=<encodedUserContact>&userData=<encodedUserData>` 3. The GET URL should be called and result printed in the console. I'm using React, so make it a react component.
0
vawogbemi avatar
vawogbemi
whoIsHiringHome
Script
@jsxImportSource https://esm.sh/react
0
vladimyr avatar
vladimyr
podcastBadge
HTTP
Console DevTools devtools.fm
0
yawnxyz avatar
yawnxyz
newsly
Email
Newsly inspired by https://kill-the-newsletter.com/ copy your email into a newsletter like substack read the newsletter here / store them into valtown you can set it so you can chat with it or send you alerts or whatever idk
1
stevekrouse avatar
stevekrouse
newStripeSubscriber
HTTP
New Stripe Subscription Handler This val processes new Stripe subscribers to Val Town Pro. It sends our team a Discord notifcation and sends a welcome email to the new subscriber. It takes a couple of steps if you'd like to set up something similar for your own Stripe account. Setup Fork this HTTP val Create a new webhook in Stripe Add your val's HTTP endpoint URL into the Stripe webhook Select customer.subscription.updated as the only event to listen to (more on this below) Add your stripe_sk_customer_readonly to your Val Town Env Variables Add your webhook's signing secret as STRIPE_WEBHOOK_SECRET to you Val Town Env Variables How the code is structured Verifies the signature to make sure it's really from Stripe Filters out only newly created subscriptions Sends off the Discord message & email Which Stripe event type to listen to Stripe sends webhooks for many different kinds of events. Relevant for us here are: customer.subscription.created (what we used to listen for) customer.subscription.updated (what we're currently listening for) The issue with customer.subscription.created is that it triggers too early, before the user's payment actually goes through. This is a problem because in early Nov 2024 we started getting credit card fraudsters testing cards using our service. We started getting lots of notifications for new subscriptions that never actually became active. Note: if anyone knows good ways to prevent that sort of behavior at the root, please let me know by commenting on this val! In order to only get notified on a valid subscription, we now subscribe to customer.subscription.updated . This event happens on any subscription change, including renewals and cancellations, so now we have to filter those events to only get new subscriptions, ie where: event.data.previous_attributes.status === 'incomplete' && event.data.object.status === 'active'
2
vawogbemi avatar
vawogbemi
eventsInNYC
HTTP
Forked from synco/eventsInNYC
0
toowired avatar
toowired
windsurf_projectContext
HTTP
@jsxImportSource https://esm.sh/react@18.2.0
0
metart43 avatar
metart43
us_election_color_scheme
HTTP
Forked from metart43/reactExample
0
ejfox avatar
ejfox
weeksummary
HTTP
@jsxImportSource https://esm.sh/react
0
spinningideas avatar
spinningideas
webpage_summarizer
HTTP
@jsxImportSource https://esm.sh/react@18.2.0
1
tvalincic avatar
tvalincic
njuskaloCrawl
Cron
Forked from kajgod/njuskaloCrawl
0
rasputinkaiser avatar
rasputinkaiser
linkInBioTemplate
HTTP
Forked from stevekrouse/linkInBioTemplate
0
ubixsnow avatar
ubixsnow
insightfulSalmonRabbit
HTTP
Forked from spinningideas/webpage_summarizer
0
tmcw avatar
tmcw
staticChess
HTTP
Forked from maxm/staticChess
0
stevedylandev avatar
stevedylandev
fetchIpfsPosts
Script
An interactive, runnable TypeScript val by stevedylandev
0