Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webhook #1346

Closed
GHRoss opened this issue Jul 1, 2024 · 10 comments
Closed

Webhook #1346

GHRoss opened this issue Jul 1, 2024 · 10 comments

Comments

@GHRoss
Copy link

GHRoss commented Jul 1, 2024

Is there an example of a webhook server? I'm looking to have an endpoint that accepts anything that's thrown at it with auth in the header that writes the request to a file or database.

@mdaneri
Copy link
Contributor

mdaneri commented Jul 1, 2024

You can find one here. It's not yet committed because it's part of #1333
https://github.com/Badgerati/Pode/blob/f16cc3a61a502485f3f2713b4c0aafd4d618def6/examples/WebHook.ps1

@GHRoss
Copy link
Author

GHRoss commented Jul 1, 2024

You can find one here. It's not yet committed because it's part of #1333 https://github.com/Badgerati/Pode/blob/f16cc3a61a502485f3f2713b4c0aafd4d618def6/examples/WebHook.ps1

Wow! What a happy coincidence! What would be the best way to add simple auth to this?

@GHRoss
Copy link
Author

GHRoss commented Jul 1, 2024

Also, would the best place to do the actual storing of the data be on line 141?

@mdaneri
Copy link
Contributor

mdaneri commented Jul 1, 2024

the easy way is to save on the file system using Save-PodeState -Path './state.json'
on line 114

$state:subscriptions.Remove($data.url)
# Saving to ./state.json
Save-PodeState -Path './state.json'`

# Respond with a status message
Write-PodeJsonResponse -Value @{ message = 'Unsubscribed successfully!' } -StatusCode 200

and on line 79

$state:subscriptions[$data.url] = $true
# Saving to ./state.json
Save-PodeState -Path './state.json'`

# Respond with a status message
Write-PodeJsonResponse -Value @{ message = 'Subscribed successfully!' }

@mdaneri
Copy link
Contributor

mdaneri commented Jul 1, 2024

for the authentication you can grab as example petstore https://github.com/Badgerati/Pode/blob/f16cc3a61a502485f3f2713b4c0aafd4d618def6/examples/PetStore/Petstore-openApi.ps1 Line 129

 New-PodeAuthScheme -ApiKey -LocationName 'api_key' | Add-PodeAuth -Name 'api_key' -Sessionless -ScriptBlock {
 

@GHRoss
Copy link
Author

GHRoss commented Jul 1, 2024

the easy way is to save on the file system using Save-PodeState -Path './state.json'
on line 114

$state:subscriptions.Remove($data.url)
# Saving to ./state.json
Save-PodeState -Path './state.json'`

# Respond with a status message
Write-PodeJsonResponse -Value @{ message = 'Unsubscribed successfully!' } -StatusCode 200

and on line 79

$state:subscriptions[$data.url] = $true
# Saving to ./state.json
Save-PodeState -Path './state.json'`

# Respond with a status message
Write-PodeJsonResponse -Value @{ message = 'Subscribed successfully!' }

Interesting! So you wouldn't use the /store endpoint?

@mdaneri
Copy link
Contributor

mdaneri commented Jul 1, 2024

Sorry, I was saving the state, not the store.
The store you can save it anywhere you like S3, File, DB, or if you want to use $state: you can do it too

@GHRoss
Copy link
Author

GHRoss commented Jul 1, 2024

Sorry, I was saving the state, not the store.
The store you can save it anywhere you like S3, File, DB, or if you want to use $state: you can do it too

Great, thank you. Just to be clear, best to add to datastore on line 141 as validation would have passed?

@mdaneri
Copy link
Contributor

mdaneri commented Jul 1, 2024

This is a sample theoretical; you don't need to print the content of your body.
Sure, It can be moved after the validation. Validation is not something that many people use

@GHRoss
Copy link
Author

GHRoss commented Jul 3, 2024

Thank you!

@GHRoss GHRoss closed this as completed Jul 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants