Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/tj/news-api

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/tj/news-api

  • v0.0.0-20200529084311-09c0fd5ad803
  • Source
  • Go
  • Socket score

Version published
Created
Source

News API

This tiny API provides subscribing and unsubscribing of users using the go-news package.

Routes

GET /subscribers

Responds with all subscribers for a newsletter, provided in the query-string parameter.

POST /subscribe

Accepts a form body with a newsletter name and subscriber and email.

GET /unsubscribe

Requires the newsletter and token query-string parameters. The token must be signed with the TOKEN_SECRET and the included token package, this ensures that only people who received an email with this token in their unsubscribe link can perform an unsubscribe.

Setup

  • Create a DynamoDB table with a Partition Key of "newsletter", and a Sort Key of "email".
  • Deploy this app however you prefer, you could use Up for example
  • Define the required environment variables:
    • TOKEN_SECRET: The secret used for signing unsubscribe tokens
    • API_TOKEN: The API token used to secure sensitive routes (GET /subscribers)
    • SUBSCRIBE_REDIRECT_URL: The redirect URL used for a successful subscription (thank you page)
    • UNSUBSCRIBE_REDIRECT_URL: The redirect URL used for a successful unsubscribe (bye bye page)
    • DYNAMO_TABLE: An optional table name, defaults to "news"

Auth

The API_TOKEN is used to restrict access to sensitive routes. You can specify it as the Basic Auth password, no username is necessary, for example:

$ export API_TOKEN=hello
$ go run main.go &
$ curl -u :slothy localhost:3000/subscribers?newsletter=blog

GoDoc

Sponsors

This project is sponsored by my GitHub sponsors:

FAQs

Package last updated on 29 May 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc