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

Support JSON requests (GET & POST) #6

Closed
neocotic opened this issue Nov 23, 2016 · 2 comments
Closed

Support JSON requests (GET & POST) #6

neocotic opened this issue Nov 23, 2016 · 2 comments
Assignees
Milestone

Comments

@neocotic
Copy link
Owner

No description provided.

@neocotic neocotic modified the milestone: 2.1.0 Nov 24, 2016
neocotic pushed a commit that referenced this issue Nov 24, 2016
@neocotic neocotic mentioned this issue Nov 24, 2016
Merged
1 task
@neocotic neocotic self-assigned this Nov 24, 2016
@neocotic
Copy link
Owner Author

I committed this change today so it should be included in the next release. I added the following to the docs which should cover how this has been supported:


IMPORTANT: When sending GET requests, by design, all information will be included in the URL of the request
This includes data as well as any credentials used to authenticate with the API. You have been warned.
This is unavoidable when sending requests in the JSONP format but, when using the JSON format, you can send POST
requests, which means that your data is sent inside the body of the request. Combine this with HTTPS and your data and
credentials cannot be sniffed over the network.

As you may have noticed; this method also accepts the following entirely optional options:

Option Description Default
format Format in which requests are sent "jsonp"
method HTTP method to be used for requests "GET"
// Does the same as specifying no options (i.e. using defaults)
yourls.connect('https://example.com/yourls-api.php', null, {
  format: 'jsonp',
  method: 'GET'
})

// Best practice if you want to secure the data you're transmitting and you've setup CORS, if needed
yourls.connect('https://example.com/yourls-api.php', {
  signature: '3002a61584'
}, {
  format: 'json',
  method: 'POST'
})

The following formats are supported with the corresponding HTTP methods:

Format HTTP Methods
json GET, POST
jsonp GET

IMPORTANT: The YOURLS server must be running version 1.5.1 or newer in order to send requests in the JSONP
format.


The new method signature for yourls.connect is as follows:

yourls.connect(url[, credentials][, options])

@neocotic
Copy link
Owner Author

This change has been included in today's 2.1.0 release.

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

1 participant