Coder Social home page Coder Social logo

Comments (10)

fogine avatar fogine commented on May 18, 2024 2

IPython uses an exclamation mark to prefix a shell command.

@eliangcs , that is certainly better, I'd rather introduce new command sh or shell instead of explanation mark which could take unquoted, squoted or dquoted string as an argument... I think it would be more transparent that way ...

The example would become:

shell echo 'some string value' | post example.com/person/1 | shell grep "abc" | post /upload 

Edit: As I think about it, the explanation mark is good as well..

from http-prompt.

eliangcs avatar eliangcs commented on May 18, 2024 1

I'm thinking of doing what xonsh does -- we try to parse the command as an HTTP Prompt command first. If it failed, we execute it like a shell command. So users can pipe to httpie or shell anyway they want:

echo 'some string value' | post example.com/person/1 | grep "abc" | post /upload 

This is basically re-implementing a shell in HTTP Prompt. I guess it won't be hard to do but will require some effort to change the code structure as I did not anticipate this requirement in the beginning of development.

from http-prompt.

gittyup2018 avatar gittyup2018 commented on May 18, 2024 1

Can you add support for <<< ? this works

HTTP/1.1 200 OK
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: *
Connection: keep-alive
Content-Encoding: gzip
Content-Length: 252
Content-Type: application/json
Date: Wed, 13 Mar 2019 07:22:56 GMT
Server: nginx

{
"args": {},
"data": "raw payload\n",
"files": {},
"form": {},
"headers": {
"Accept": "application/json, /",
"Accept-Encoding": "gzip, deflate",
"Content-Length": "12",
"Content-Type": "application/json",
"Host": "httpbin.org",
"User-Agent": "HTTPie/1.0.2"
},
"json": null,
"url": "https://httpbin.org/post"
}

http httpbin.org/post <<< 'raw payload'

Credit:

httpie/cli#356

henrik242 commented Jan 27, 2017

You can also use http httpbin.org/post <<< 'raw payload'

from http-prompt.

BoboTiG avatar BoboTiG commented on May 18, 2024 1

The feature has been added to HTTPie (--raw option, https://github.com/httpie/httpie/tree/master/docs#request-data-via---raw). It will be made available for HTTP Prompt for the next HTTPie release (soon).

from http-prompt.

fogine avatar fogine commented on May 18, 2024

we try to parse the command as an HTTP Prompt command first. If it failed, we execute it like a shell command.

@eliangcs , that would make http-prompt quite flexible. I've positive viewpoint on this idea.

but will require some effort to change the code structure

It'd introduce major changes to lexer / grammar definitions. I think, it would need quite a lot of work.

Edit: Maybe, could you review the #74 PR first so I know that I'm on good road? It doesn't need to be merged now. I'd try to make changes in order to support "fallback to shell command" feature which you've introduced... Or do you want to make the major changes by yourself, @eliangcs ?

from http-prompt.

eliangcs avatar eliangcs commented on May 18, 2024

@fogine Sure, I'll start review #74 soon when I have time.

Executing shell commands is easy, but I'm not sure how to deal with the lexer. How do you implement a lexer that is compatible with both shell and HTTP Prompt syntax?

from http-prompt.

fogine avatar fogine commented on May 18, 2024

How do you implement a lexer that is compatible with both shell and HTTP Prompt syntax?

@eliangcs , I haven't fully thought this through yet however currently I think of defining BashLexer as fallback when there is no match for any of the main http-prompt lexer definitions (which I think is possible).
Downside of this is that we would basically lose "SyntaxError" highlighting style which would be replaced by bash's Text style.

The same issue described above applies for command execution - that we'll have to execute every invalid command as bash command which can lead to unexpected behavior (potentially dangerous)... won't we?

from http-prompt.

eliangcs avatar eliangcs commented on May 18, 2024

@fogine I think you're right. Executing any invalid command as a bash command is unpredictable and dangerous. Or we can try IPython's approach. IPython uses an exclamation mark to prefix a shell command. So the previous example becomes:

!echo 'some string value' | post example.com/person/1 | !grep "abc" | post /upload 

from http-prompt.

fogine avatar fogine commented on May 18, 2024

So, do we give the explanation mark a go, @eliangcs ?
I haven't come with better idea so I'd implement it.

from http-prompt.

eliangcs avatar eliangcs commented on May 18, 2024

@fogine yes, feel free to do this 👍

from http-prompt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.