Carbon as an API #1340
Replies: 42 comments 2 replies
-
I thought about the same and found this related issue: #179 |
Beta Was this translation helpful? Give feedback.
-
Cool idea! #179 seems to be focused on rendering an embeddable editor. From your description, it seems to me that this is more tuned towards an API the returns the image data. Am I understanding that correctly? |
Beta Was this translation helpful? Give feedback.
-
Not sure what the use case might be though 😂 If you find a use case, keep this open otherwise we have other issue that requests embedding it. I can't think of anything useful though, what I needed was embeddable editor only. I just kinda put it the wrong way. The embeddable editor would have the specified theme, font size & all the other features but it will be a replacement of Github Gist for Medium or any other Blog so we can select text just like we do on the Carbon website rather than an actual Image. As for the API, if its there then extensions might be easier to make. Just send a https://api.carbon.now.sh?code={console.log('GIMME A HELL YEAH')}&lang=js&theme=monokai & it will download the image in the same directory & after downloading it will then delete it from the server or imgur whatever you prefer. I am assuming the current way might be a little bit tedious without the API like
Idk if its gonna be required or there are any other use cases. But I can't think of anything else at this moment. So close it if you want. |
Beta Was this translation helpful? Give feedback.
-
@deadcoder0904 Why sending a POST request and use query parameters? Better use POST with JSON as payload with your desired settings and code. |
Beta Was this translation helpful? Give feedback.
-
gotcha @deadcoder0904 , I understand what you mean now. Well if you're primarily interested in the embeddable part, keep an eye on #179 because that's exactly what we're working on over there! As for the image API aspect, I agree that could be useful for building extensions! Fortunately with #213 we've ended up needing to implement most of this already. @KennethWussmann the way that is shaping up, it will be similar to what you're talking about. Client can POST with a base64 encoded state string or a state object and the response JSON will include the image 👍 |
Beta Was this translation helpful? Give feedback.
-
I love the idea, a service would be so useful. The downside right now is that it's some hassle to update. For instance i'm using carbon on a github project: https://github.com/drcmda/react-contextual But silly like i am i set it to javascript, not jsx, so all the images are mangled, on top of it there's a bug i oversaw. It means i have to go through all the trouble again, preparing code in the editor so that it looks good even though prettier wants it to stretch, making sure all images have the same width (something i couldn't find out how to do with the settings, so i inserted a long blank-space line in them), etc. If you could link to an image generator service that creates the png on the fly with some caching maybe, that would make it so much easier to maintain a series of snippets ...
Or even better if it could point to a plain-text url
|
Beta Was this translation helpful? Give feedback.
-
Hi, I kinda wanted to use carbon for auto screenshotting images of my code whenever I posted them into an IO service. I decided to self host an API I wrote using puppeteer. I know it's a bit basic as of now, but I want to know if anyone wants to help with PRs or issues. (this is my first node project btw) EDIT: Currently a lot of the features are supported but some issues like long typing times (because puppeteer types it out char by char and not pasting the code into the box) and drop shadow configuration aren't there yet. You can still however use code, set background colors and padding and more. EDIT 2: Just realized I could use the |
Beta Was this translation helpful? Give feedback.
-
The Image generated via Carbon is awesome. But its not good for accessibility & I think blind people would not be able to read the code so for that I think a Service where we can embed beautiful looking code with colour formatting, themes but still accessible. Something like CodePen, CodeSandbox or Github Gist but just that you get beautiful looking code & can copy/paste the code & its still accessible. I just hope this doesn't overload your server though. Or as this is an open source project maybe someone like Now would give it for free. Just an idea. Not sure how embedding works. |
Beta Was this translation helpful? Give feedback.
-
Running carbon locally in docker and outputting our company code automatically to our document server would be a killer feature. Devs won't do this thing by themselves and we will need to automate this process. Great for versioning, and onboarding. |
Beta Was this translation helpful? Give feedback.
-
I'm currently using it to embed code automatically in chat clients (like Discord, Whatsapp, etc): Since most clients don't support embeds, I would find an API useful. |
Beta Was this translation helpful? Give feedback.
-
What's the progress in the Carbon API? |
Beta Was this translation helpful? Give feedback.
-
Hey, we would like to use Carbon via an API for the 30-seconds projects aswell! Is there any progress on this? |
Beta Was this translation helpful? Give feedback.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
-
Why not send a file using API? Instead of sending data in JSON format or inside the URL. The concept with handling the file it start forward the user can send a POST request to the API and carbon can read the content inside file and return the beautiful formatted code in the form of image. Benefits
|
Beta Was this translation helpful? Give feedback.
-
I was learning Pyppeteer so thought of writing an API using Python and Flask. |
Beta Was this translation helpful? Give feedback.
-
Trying to create something similar with Also check out Themeify, A Google chrome extension that uses |
Beta Was this translation helpful? Give feedback.
-
So, I wanted to use this to convert code to an image and send it on discord. Any api's to use with nodejs? |
Beta Was this translation helpful? Give feedback.
-
you can use |
Beta Was this translation helpful? Give feedback.
-
Hey folks, Carbon has always had an API, which you can see if you generate a screenshot using Safari. It works by passing an encoded JSON blob to https://carbon.now.sh/api/image. I really would like to open-source the API, but I just haven't had time to accurately document it. Hopefully I'll have time to release the first class-API soon. |
Beta Was this translation helpful? Give feedback.
-
I created some utility, which returns a blob with a image (generated by carbon.now.sh) based on github code snippet: |
Beta Was this translation helpful? Give feedback.
-
@mfix22 I'd be more than happy to help with this, so long as I know which file(s) needs to be documented (I assume this one? https://github.com/carbon-app/carbon/blob/main/api/image/index.js) |
Beta Was this translation helpful? Give feedback.
-
Yes 👍 |
Beta Was this translation helpful? Give feedback.
-
Any update on this? @tycrek @mfix22 I've successfully tried the API with some catches (I'm not really familiar with Next.js code):
Btw, the code has moved to pages/api/image/[id].js since a327b44. |
Beta Was this translation helpful? Give feedback.
-
Would it be possible to generate an embed to a github gist and pass theme and background color parameters to it? Would be great for embedding in Medium posts |
Beta Was this translation helpful? Give feedback.
-
@DeveloperBlue This is already a supported feature. 👍 E.g. https://carbon.now.sh/embed/3208813b324d82a9ebd197e4b1c3bae8?bg=blue |
Beta Was this translation helpful? Give feedback.
-
Fantastic, is there any API documentation I can find for this and other parameters? I can't seem to get https://carbon.now.sh/embed/3208813b324d82a9ebd197e4b1c3bae8?bg=0077db&theme=nord working. |
Beta Was this translation helpful? Give feedback.
-
I know this is a bit of an aging thread now, but I was just looking for the same thing and here's what I've discovered so far. https://carbon.now.sh/embed/ {GitHub_Gist_ID} ? {params}
|
Beta Was this translation helpful? Give feedback.
-
Thanks for all the input, everyone. I’m looking to release v2 of carbon-now-cli this year, and one of the things I’d like to have the most is not having to use Puppeteer inside the CLI. After going through this entire thread + several other open/closed PRs/issues, am I right to assume that, as of March 2023, there is no a) official Carbon API yet Or am I mistaken? Thank you all in advance; much appreciated. |
Beta Was this translation helpful? Give feedback.
-
Also related to the comment above, also still waiting for an API solution, is one still not available or anyone made an API version of this? |
Beta Was this translation helpful? Give feedback.
-
Send the code & it returns a dynamic image. It can have all the other options as well. That way it would be easy to embed it dynamically with just code. I can't think of any other use cases right now. What do you think?
Beta Was this translation helpful? Give feedback.
All reactions