René's URL Explorer Experiment


Title: Support Promises for API calls · Issue #90 · PlayFab/JavaScriptSDK · GitHub

Open Graph Title: Support Promises for API calls · Issue #90 · PlayFab/JavaScriptSDK

X Title: Support Promises for API calls · Issue #90 · PlayFab/JavaScriptSDK

Description: I've been using both this SDK and the NodeJS SDK extensively for a few months now, and I've found that the SDKs are much easier to use when API calls are promise-based. I've been using a wrapper function that provides this functionality,...

Open Graph Description: I've been using both this SDK and the NodeJS SDK extensively for a few months now, and I've found that the SDKs are much easier to use when API calls are promise-based. I've been using a wrapper fu...

X Description: I've been using both this SDK and the NodeJS SDK extensively for a few months now, and I've found that the SDKs are much easier to use when API calls are promise-based. I've been using ...

Opengraph URL: https://github.com/PlayFab/JavaScriptSDK/issues/90

X: @github

direct link

Domain: patch-diff.githubusercontent.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Support Promises for API calls","articleBody":"I've been using both this SDK and the NodeJS SDK extensively for a few months now, and I've found that the SDKs are much easier to use when API calls are promise-based. I've been using a wrapper function that provides this functionality, which works fine but is not ideal. That looks something like this (shortened for brevity)  \r\n\r\n```javascript\r\nfunction playfabAPI(endpoint, requestObject) {\r\n    return new Promise(function(resolve, reject) {\r\n        PlayFabClientSDK[endpoint](requestObject, function(error, result) {\r\n            if (error !== null) {\r\n                // Request error\r\n                return reject(new Error(error));\r\n            }\r\n            else if (result \u0026\u0026 result[\"code\"] == 200) {\r\n                // Request successful\r\n                return resolve(result);\r\n            }\r\n            else {\r\n                // Non-200 HTTP status\r\n                return reject(new Error(result.status));\r\n            }\r\n        });\r\n    });\r\n}\r\n```  \r\n\r\nThis makes for cleaner code, adds useful functionality, and eliminates a lot of redundant error checking code. The current request functions are consistent enough for this to work in most cases so far but I'm a bit wary of using it in production. What I would propose is to implement this either alongside the current format, or as an additional SDK/script, for compatibility reasons.  \r\n\r\n\u003chr\u003e \r\n\r\n### Example of how this change could be implemented in a given function:  \r\n\r\n#### Current\r\n```javascript\r\nexports.UpdateUserData = function (request, callback) {\r\n    if (PlayFab._internalSettings.sessionTicket == null) {\r\n        throw \"Must be logged in to call this method\";\r\n    }\r\n    PlayFab.MakeRequest(\r\n        PlayFab.GetServerUrl() + \"/Client/UpdateUserData\",\r\n        request,\r\n        \"X-Authorization\",\r\n        PlayFab._internalSettings.sessionTicket,\r\n        function (error, result) {\r\n            if (callback != null) {\r\n                callback(error, result);\r\n            }\r\n        },\r\n    );\r\n};\r\n```\r\n\r\n#### Proposed\r\n```javascript\r\nexports.UpdateUserData = function (request)\r\n{\r\n    return new Promise((resolve, reject) =\u003e {\r\n        if (PlayFab._internalSettings.sessionTicket == null) {\r\n            throw \"Must be logged in to call this method\";\r\n        }\r\n        PlayFab.MakeRequest(\r\n            PlayFab.GetServerUrl() + \"/Client/UpdateUserData\",\r\n            request,\r\n            \"X-Authorization\",\r\n            PlayFab._internalSettings.sessionTicket,\r\n            (error, result) =\u003e {\r\n                if (error !== null) {\r\n                    return reject(new Error(error));\r\n                }\r\n                else if (result \u0026\u0026 result[\"code\"] == 200) {\r\n                    return resolve(result);\r\n                }\r\n                else {\r\n                    return reject(new Error(result.status));\r\n                }\r\n            },\r\n        );\r\n    });\r\n};\r\n```  \r\n\r\n\u003chr\u003e \r\n\r\n### Example usage of current vs proposed usage:  \r\n#### Current\r\n```javascript\r\nPlayFabClientSDK.UpdateUserData(requestParameters, function(error, result) {\r\n    // Check for + handle errors... \r\n    // Handle result...\r\n});\r\n```\r\n#### Proposed\r\n```javascript\r\nPlayFabClientSDK.UpdateUserData(requestParameters).then((userDataResult) =\u003e {\r\n    // Handle userDataResult...\r\n}).catch((error) =\u003e {\r\n    // Handle errors... \r\n});\r\n```\r\n\r\nThis would also have the added benefit of allowing the use of async/await which can greatly simplify code structure, e.g. when chaining requests\r\n```javascript\r\n(async function() {\r\n    const userDataResult = await PlayFabClientSDK.UpdateUserData(requestParameters);\r\n    // Handle userDataResult/make additional API requests\r\n})();\r\n```\r\n\r\n\u003chr\u003e\r\n\r\nLet me know what you guys think. Is this something that would be better served using the SDK generator with a custom config, or would it be feasible to get an official implementation? ","author":{"url":"https://github.com/403-Fruit","@type":"Person","name":"403-Fruit"},"datePublished":"2020-12-02T23:18:10.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/90/JavaScriptSDK/issues/90"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:568ab3c5-7dcf-1d56-ab72-4ca7e8d8c2a6
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id877E:3F65C8:FF99FF:1526B89:69717AED
html-safe-nonce086a53fdd62e12a77ea2775a234989433cddc050236ffd82743ada28cc782f32
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NzdFOjNGNjVDODpGRjk5RkY6MTUyNkI4OTo2OTcxN0FFRCIsInZpc2l0b3JfaWQiOiI2ODM3NTUzNTM0MzEzMDAzNzU3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac3cf45d7fc1bfffe191970b360e0dd2c9e97387111d04fed14fc85d024d2e58ad
hovercard-subject-tagissue:755683000
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/PlayFab/JavaScriptSDK/90/issue_layout
twitter:imagehttps://opengraph.githubassets.com/1f0984698becf34038ebcfb3621ec858cf17f802629bc427dd144a32a139b689/PlayFab/JavaScriptSDK/issues/90
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/1f0984698becf34038ebcfb3621ec858cf17f802629bc427dd144a32a139b689/PlayFab/JavaScriptSDK/issues/90
og:image:altI've been using both this SDK and the NodeJS SDK extensively for a few months now, and I've found that the SDKs are much easier to use when API calls are promise-based. I've been using a wrapper fu...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:username403-Fruit
hostnamegithub.com
expected-hostnamegithub.com
None102ab681b33bed6a87d35dc54dd8200470d7e01648f08979e84415ab67d611aa
turbo-cache-controlno-preview
go-importgithub.com/PlayFab/JavaScriptSDK git https://github.com/PlayFab/JavaScriptSDK.git
octolytics-dimension-user_id7634333
octolytics-dimension-user_loginPlayFab
octolytics-dimension-repository_id31617208
octolytics-dimension-repository_nwoPlayFab/JavaScriptSDK
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id31617208
octolytics-dimension-repository_network_root_nwoPlayFab/JavaScriptSDK
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release6a660b76f271bda19afb9f5242b473bfee637a5a
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://patch-diff.githubusercontent.com/PlayFab/JavaScriptSDK/issues/90#start-of-content
https://patch-diff.githubusercontent.com/
Sign in https://patch-diff.githubusercontent.com/login?return_to=https%3A%2F%2Fgithub.com%2FPlayFab%2FJavaScriptSDK%2Fissues%2F90
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://patch-diff.githubusercontent.com/login?return_to=https%3A%2F%2Fgithub.com%2FPlayFab%2FJavaScriptSDK%2Fissues%2F90
Sign up https://patch-diff.githubusercontent.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=PlayFab%2FJavaScriptSDK
Reloadhttps://patch-diff.githubusercontent.com/PlayFab/JavaScriptSDK/issues/90
Reloadhttps://patch-diff.githubusercontent.com/PlayFab/JavaScriptSDK/issues/90
Reloadhttps://patch-diff.githubusercontent.com/PlayFab/JavaScriptSDK/issues/90
PlayFab https://patch-diff.githubusercontent.com/PlayFab
JavaScriptSDKhttps://patch-diff.githubusercontent.com/PlayFab/JavaScriptSDK
Notifications https://patch-diff.githubusercontent.com/login?return_to=%2FPlayFab%2FJavaScriptSDK
Fork 30 https://patch-diff.githubusercontent.com/login?return_to=%2FPlayFab%2FJavaScriptSDK
Star 48 https://patch-diff.githubusercontent.com/login?return_to=%2FPlayFab%2FJavaScriptSDK
Code https://patch-diff.githubusercontent.com/PlayFab/JavaScriptSDK
Issues 4 https://patch-diff.githubusercontent.com/PlayFab/JavaScriptSDK/issues
Pull requests 1 https://patch-diff.githubusercontent.com/PlayFab/JavaScriptSDK/pulls
Actions https://patch-diff.githubusercontent.com/PlayFab/JavaScriptSDK/actions
Projects 0 https://patch-diff.githubusercontent.com/PlayFab/JavaScriptSDK/projects
Wiki https://patch-diff.githubusercontent.com/PlayFab/JavaScriptSDK/wiki
Security Uh oh! There was an error while loading. Please reload this page. https://patch-diff.githubusercontent.com/PlayFab/JavaScriptSDK/security
Please reload this pagehttps://patch-diff.githubusercontent.com/PlayFab/JavaScriptSDK/issues/90
Insights https://patch-diff.githubusercontent.com/PlayFab/JavaScriptSDK/pulse
Code https://patch-diff.githubusercontent.com/PlayFab/JavaScriptSDK
Issues https://patch-diff.githubusercontent.com/PlayFab/JavaScriptSDK/issues
Pull requests https://patch-diff.githubusercontent.com/PlayFab/JavaScriptSDK/pulls
Actions https://patch-diff.githubusercontent.com/PlayFab/JavaScriptSDK/actions
Projects https://patch-diff.githubusercontent.com/PlayFab/JavaScriptSDK/projects
Wiki https://patch-diff.githubusercontent.com/PlayFab/JavaScriptSDK/wiki
Security https://patch-diff.githubusercontent.com/PlayFab/JavaScriptSDK/security
Insights https://patch-diff.githubusercontent.com/PlayFab/JavaScriptSDK/pulse
New issuehttps://patch-diff.githubusercontent.com/login?return_to=https://github.com/PlayFab/JavaScriptSDK/issues/90
New issuehttps://patch-diff.githubusercontent.com/login?return_to=https://github.com/PlayFab/JavaScriptSDK/issues/90
Support Promises for API callshttps://patch-diff.githubusercontent.com/PlayFab/JavaScriptSDK/issues/90#top
https://github.com/403-Fruit
https://github.com/403-Fruit
403-Fruithttps://github.com/403-Fruit
on Dec 2, 2020https://github.com/PlayFab/JavaScriptSDK/issues/90#issue-755683000
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.