Skip to content

Allowing custom http method names

Compare
Choose a tag to compare
@razshare razshare released this 27 Jul 10:26
· 13 commits to main since this release

Changes

  • It is now possible to set the http method of your source()
<!-- +page.svelte -->
<script>
  import { source } from 'sveltekit-sse'
  const connection = source('/issue-55/events', {
    options: {
      method: 'GET',  // The default is POST.
    },
  })
  const message = connection.select('message')
</script>

<h3>{$message}</h3>
import { produce } from 'sveltekit-sse'
import { delay } from '$lib/delay.js'

export async function GET() { // Then you can use GET here.
  return produce(async function start({ emit }) {
    while (true) {
      const { error } = emit('message', `${Date.now()}`)
      if (error) {
        return
      }
      await delay(1000)
    }
  })
}