Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

Short and concise example #244

Closed
musicsmithnz opened this issue Mar 23, 2018 · 10 comments
Closed

Short and concise example #244

musicsmithnz opened this issue Mar 23, 2018 · 10 comments

Comments

@musicsmithnz
Copy link

feel free to close this off, but why are the examples around 1000lines long? it seems to me that any example that requires sifting through that much code is no longer helpful.

i am looking to do two things, set up a ipfs node to serve an api, and a client to make requests. i haven't found any examples that connect these two together.

this example led me to interface-ipfs-core/ repo. but it adds the file to a local instance, not a remote api. i'm having trouble finding an answer.
https://github.com/ipfs/js-ipfs/tree/master/examples/ipfs-101

@musicsmithnz
Copy link
Author

musicsmithnz commented Mar 23, 2018

i found out the two packages i needed. i got what i wanted with go-ipfs which has an inbuilt api server, and then using the js-ipfs-api on top of this.

Would it be helpful for others if a wrote a short tutorial on this? As i think this must be an extremely common usecase and it would help to have all the information in one place rather than searching through all the different ipfs github repos.

@victorb
Copy link
Contributor

victorb commented Mar 23, 2018

Thanks all lot for writing this issue, it's true that our tutorials are sometimes long and not in the place where you might expect it, we're still trying to improve the discovery part of finding examples/tutorials and guides but we're not there yet.

For JavaScript/IPFS tutorials and guides, you probably want to look here: https://github.com/ipfs/js-ipfs/tree/master/examples

interface-ipfs-core is basically just for defining a interface for API and core clients so you can switch in-between them.

We're right in the middle of revamping most of our documentation, and @Mr0grog probably have a better idea where a short tutorial on this would live.

@Mr0grog
Copy link

Mr0grog commented Mar 23, 2018

Hi @musicsmithnz, I think a clear, concise tutorial on that would be really useful. For now, I’d say it probably fits best in the js-ipfs-api repo’s examples folder.

I think part of the problem here is just discoverability. Using the *-ipfs-api projects to manage a local IPFS instance is probably the main, generalized path people should be using, but it’s hard to figure that out without someone telling you, and there are too many repos on GitHub to make finding it very obvious or easy.

To that end, we’re starting to build a whole new docs site one of the early priorities is to organize and link the different tools and examples from a single place in a clear way. So I think what we’d want to do first is have that tutorial as part of js-ipfs-api and link it from the new site. Would you be interested in writing the tutorial there and working to get it incorporated in the new docs site?

@musicsmithnz
Copy link
Author

Hey guys! Thanks for confirming this issue. I sort of felt bad about not being able to figure out how to set up a basic API! But really, it does make it confusing when there is near 200 repos under IPFS and you have to potentially search half a dozen docs before you come to the answer you need. Which is roughly what I did, and it worked, but took longer to find the answers than necessary.

I will work at this, I'll write out a short example/tutorial on setting up and using the API, maybe implementing CRUD operations I suppose. Perhaps I could make a bonus example adding encryption, which would enable storing sensitive private data.

@alanshaw alanshaw changed the title examples Short and concise example Jun 8, 2018
@alanshaw
Copy link
Contributor

alanshaw commented Jun 8, 2018

@musicsmithnz did you get anywhere with this? We'd still love to see a PR!

@alchmy
Copy link

alchmy commented Jun 8, 2018

I am @musicsmithnz (other account)
I have been on other things. But thanks for reminding me about this. I love writing tutorials. I will look into doing this soon.

@alchmy
Copy link

alchmy commented Jun 9, 2018

So I have been playing around with the API, and it works great on single files, but i dont know if there is any way of using recursive directories with this API, i know it works in JS, and locally on the command line, but I'm not sure how this would work with Curl. I have tried several other things in addition to below(single file), such as using -T or --create-dirs.

curl -F file=@my_file 'http://123.29.19.154:4108/api/v0/add?recursive=true&wrap-with-directory=true'

@alchmy
Copy link

alchmy commented Jun 9, 2018

I could also loop through adding the files, but this doesn't give me the hash of the whole directory and upload it to ipfs, so its no good for a database that you want to linked

@musicsmithnz
Copy link
Author

musicsmithnz commented Jun 9, 2018

I am @alchmy in case anyone doubted.

I am also having trouble with the recursive add in js-ipfs. I don't remember if I had this working before, but the docs don't include a recursive add example, so I'm not sure if i need to put something in the content parameter? Here is what I have.

directory_name= "some_directory_name"
ipfs.files.add(
        [{
            path: directory_name
        }], {
            wrapWithDirectory: true,
            recursive: true
        },
        function (err, files){
            console.log( err )
        }
    )

The response I get is just uploading an empty directory: the default response for no content. But I don't know what should exist under content... you can't put a directory into a blob I assume.

@achingbrain
Copy link
Collaborator

This issue is now quite stale. The ipfs-101 example is 24 lines long - please open a PR against ipfs/js-ipfs if there are more improvements to be made.

For questions about how to use the API, please start a thread at https://discuss.ipfs.io/

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants