0

I've recently transitioned into API developer writing at my job and would like to create an option to choose different program languages for our sample code. As of now, we only provide cURL code samples, but I would like to expand our options. I really like how Stripe API accomplishes this as they allow you to push a button for the language option which in turn updates the sample code. Postman also provides an option to changes the language of your sample code. I'm an extreme novice when it comes to this stuff, but after doing a little research, I believe that Stripe uses javascript to change the samples.

We're currently using Slate's static site generator of our page.

I figured that having the ability to change the speaking language of a site was similar to what I'm looking for and already found some useful information here in stack overflow. I know I can create the buttons and navbar, but it's the scripting on the back-end that I'll have some trouble with.

Hopefully someone can point me in the right direction to get started. Thank you in advance and I apologize if I wasn't clear enough as I'm totally new to all this.

  • This is done by manually inputting all of the code samples, and programatically showing the sample for the language the user selects. – user229044 Aug 27 '18 at 13:15

1 Answers1

0

As you surely figured out, Stripe has different URL for different language. To get data depending on the URL they surely use AJAX and depending on the request they return data from

  1. From a static file saved in their server
  2. From a database (which is what i recommend)

Now you can do the same. But you have

  1. Write your site with lot of JS to retrieve data through AJAX and display it. May be using Angular or React;
  2. Write request and responder on your backend to respond to request for a different sample code as Stripe do maybe a request like http://example.com/api/code/sample/:language where languageis the parameter you'll use to retrieve data from database or static file
mcssym
  • 956
  • 5
  • 8
  • Thanks for this. The solution was actually much easier than I thought since we're using Slate which already has this feature built in. It's really just a matter adding the language tabs and including the specific language code in your Markdown file. – Mansa Gills Aug 27 '18 at 20:10