Git Product home page Git Product logo

dothttp's Introduction

Inspiration

With the rise in usage of microservices, Making http requests is essential job of most devs. For these, there are multiple options like curl, insomnia postman. My Ideal choice is to use curl but problems with it is, having no history and no easy way to save and rerun. Postman solves that problem, but once user logs in(earlier it used to be optional, now its mandatory), it stores all request metadata(body/headers/urls/credentails) to their servers although it helps solve using it across multiple devices, backup but it could be potential security loop hole if they can access it. (now a days, postman desktop is super slow also).

This project aims to solve save&reuse requests, maintaining history and no sync in proprietery servers (although you can achive sync via commiting http files into git).

GOAL

dothttp will provide simple, cleaner architecture for making http requests. It uses xtext (eclipse developed dsl) to build a custom dsl.

Documentation

More information or docs can be cound at https://docs.dothttp.dev


Go through this example for better understanding. for babysteps click here

# users.http

#!/usr/bin/env /home/prasanth/cedric05/dothttp/dist/dothttp-cli

# this is comment

// this is also a comment

/*
   this is multi line
   comment
*/

# http file can have multiple requests, name tag/annotation is used to identify
@name("fetch 100 users, skip first 50")

# makes are get request, with url `https://req.dothttp.dev/user`
GET https://req.dothttp.dev/user

# below is an header example
"Authorization": "Basic dXNlcm5hbWU6cGFzc3dvcmQ="

# below is how you set url params '?' --> signifies url quary param
? ("fetch", "100") #
? ("skip", "50")
? projection, name
? projection, org
? projection, location




# makes are post request, with url `https://req.dothttp.dev/user`
POST https://req.dothttp.dev/user

basicauth('username', 'password')
/*
   below defines payload for the post request.
   json --> signifies payload is json data
*/
json({
    "name": "{{name=adam}}", # name is templated, if spcified via env or property, it will be replaced
    "org": "dothttp",
    "location": "Hyderabad",
    # "interests": ["exploring", "listening to music"],
})



# makes put request, with url `https://req.dothttp.dev/user/1`
PUT https://req.dothttp.dev/post

# define headers in .dothttp.json with env
basicauth("{{username}}, "{{password}}")

# posts with urlencoded
data({
    "name": "Adam A",
    "org": "dothttp",
    "location": "Hyderabad",
    "interests": ["exploring", "listening to music"],
})

// or use below one
// data('name=Adam+A&org=dothttp&location=Hyderabad&interests=%5B%27exploring%27%2C+%27listening+to+music%27%5D')

KICKSTART

From pypi

pip install dothttp-req==0.0.10

From source

git clone [email protected]:cedric05/dothttp.git
cd dothttp

python3 -m pip install pipenv
pipenv install

python3.9

python3 -m dothttp examples/dothttpazure.http

docker

docker build -t dothttp .
docker run -it --rm dothttp

whalebrew

docker run -it --rm dothttp

Features

  1. easy and cleaner http syntax
  2. variable substitution with property file
  3. generates curl from http for easy sharing
docker build -t dothttp .
whalebrew install dothttp
dothttp examples/dothttpazure.http

First DotHttpRequest and more

GET "http://localhost:8000/get"

dothttp get.http or python -m dothttp get.http

Run

dothttp simple.http

prints

{
  "args": {},
  "headers": {
    "Accept-Encoding": "identity",
    "Host": "httpbin.org",
    "User-Agent": "python-urllib3/1.26.3",
    "X-Amzn-Trace-Id": "Root=1-6022266a-20fb552e530ba3d90c75be6d"
  },
  "origin": "117.216.243.24",
  "url": "http://localhost:8000/get"
}

POST request

POST "http://localhost:8000/post"
{
  "args": {},
  "data": "",
  "files": {},
  "form": {},
  "headers": {
    "Accept-Encoding": "identity",
    "Content-Length": "0",
    "Host": "httpbin.org",
    "User-Agent": "python-urllib3/1.26.3",
    "X-Amzn-Trace-Id": "Root=1-602228fa-3c3ed5213b6d8c2d2a223148"
  },
  "json": null,
  "origin": "117.216.243.24",
  "url": "http://localhost:8000/post"
}

similarly, other methodsGET, POST, OPTIONS, DELETE, CONNECT, PUT, HEAD, TRACE support is available.

Query

query params can be added to request by specifying query ( "key", "value") ? "key", "value" ? "key": "value" ? "key"= "value" all four are accepted. going with query("hi", "hi2) is more readable. ?"key"= "value" is more concise

Payload

user can specify payload by mentioning below four forms (for various scenarios).

  • data("ram")

    user can also mention its content-type with data("ram", "text/plain")

  • data({"key": "value"}) for form input.

  • json({"key": "value"}) for json payload.

  • fileinput("path/to/file", "type") uploads file as payload (type is optional).

  • files(("photo", "path/to/file/photo.jpg", "image/jpeg"), ("photo details", '{"name":"prasanth"}', "application/json") )

    for multipart upload dothttp will figure out content type by going through file/data, when type is not mentioned.

Comments

dothttp will use # for commenting entire line.

  1. // line comment. follows java, javascript
  2. # line comment. follows python's comment style
  3. /* */ multi line comment. follows java/javascript style

Templating

POST 'http://localhost:8000/post'
? ("{{key}}", "{{value}}")
data('{"{{key}}" :"{{value}}"}', 'application/json')
  • specify variable values through property file (sample.json).
    • user can define environments and can activate multiple environments at a time

    • dothttp by default will read variables from "*" section

    • for example dothttp --property-file path/to/file.json --env ram chandra

      will activate * section properties, ram section properties and chandra section properties dothttp --env ram chandra will activate * section properties, ram section properties and chandra section properties from .dothttp.json in httpfile name space

  • through command line dothttp --property key=ram value=ranga will replace {{ram}} to ranga from the file
  • through file itself. (will be helpful for default properties)
POST 'https://{{host=httpbin.org}}/post'

Headers

User can define headers in below three formats

  1. header('content-type', 'application/json') readable
  2. 'content-type': 'application/json' concise
  3. property file headers section from property-file can also be used. in most scenarios, headers section will be common for a host. having them in property file would ease them.

Authentication

BasicAuth

basicauth('username','password')' --> will compute add respective headers.

DigestAuth

digestauth('username','password')' --> will compute add respective headers.

NtlmAuth

ntlmauth('username','password')' --> will compute add respective headers.

Property file

{
  "*": {
    "host": "httpbin.org"
  },
  "headers": {
    "content-type": "plain/text"
  },
  "preprod": {
    "host": "preprod.httpbin.org"
  }
}

Special sections in property file

  1. * section in property file will be activated once user specifies property file if user didn't specifiy file and .dothttp.json exists, it will be activated
  2. headers once a property file is activated. headers from property file will be added to request by default without user having to specify in .http file

Formatter (experimental phase)

dothttp can format a http file using below command dothttp -fmt examples/dothttpazure.http --experimental or dothttp --format examples/dothttpazure.http --experimental

to print to command line

dothttp --format examples/dothttpazure.http --experimental --stdout

Editor support

syntax highlighting for visual studio code is supported via dothttp-code

Command line options

usage: dothttp [-h] [--curl] [--property-file PROPERTY_FILE] [--no-cookie] [--env ENV [ENV ...]] [--debug] [--info] [--format] [--stdout]
               [--property PROPERTY [PROPERTY ...]]
               file

http requests for humans

optional arguments:
  -h, --help            show this help message and exit

general:
  --curl                generates curl script
  --no-cookie, -nc      cookie storage is disabled
  --debug, -d           debug will enable logs and exceptions
  --info, -i            more information
  file                  http file

property:
  --property-file PROPERTY_FILE, -p PROPERTY_FILE
                        property file
  --env ENV [ENV ...], -e ENV [ENV ...]
                        environment to select in property file. properties will be enabled on FIFO
  --property PROPERTY [PROPERTY ...]
                        list of property's

format:
  --format, -fmt        formatter
  --stdout              print to commandline

checkout examples


Vscode alternatives


Non Vscode alternatives

dothttp's People

Contributors

cedric05 avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

dothttp's Issues

extend request with other request

usually having to redefine auth stuff multiple times is not a good approach.

@name(base)
https://httpbin.org/post
Authorization: "some key"

@name(base2) : base
https://httpbin.org/post

for base2 Authorization should be set in reference to extend

tests

  • for postman import
    • wrong url
    • working url with wrong params
    • save, not save
    • correct url
    • forms
    • data
    • json
  • for content execute
    • fail scenarios
      • wrong input
      • env/properties (env shound not consider)
    • pass
  • targets
    • pass
      • add url along with name
      • windows target, linux target
    • fail
      • error message, with error range

Support String join

commenting out few parts in json works seemlessly. but with data payload it is not possible to add comments in between as it is an entire string.

POST https://htppbin.org/post
data('this is 
it has few lines which can be added or commented
text')

if we support multiple strings in data, we would be able to comment few parts

POST https://htppbin.org/post
data('this is '
//it has few lines which can be added or commented
'text')

should be same as

POST https://htppbin.org/post
data('this is text')

This will help xml and other language payloads as well.

Accept incomplete url

Currently http file will not allow incomplete url. Its has to start with http or https.

[windows] multipart with content-type not specified is taking forever with visual studio extension

This request is finishing first

POST "http://127.0.0.1:3000/api/v1/attachments/upload"

files(
    ('org_id', 'lFkBv4jn', 'plain/text'),
    ('parent_id', 'lFkBv4jn', 'plain/text'),
    ('author', 'UOLG-F0l', 'plain/text'),
    ('file', "D:\projects\cedric05-data-storage-api-java\apis\put.http", 'plain/text')
)

This request is taking time

POST "http://127.0.0.1:3000/api/v1/attachments/upload"

files(
    ('org_id', 'lFkBv4jn', ),
    ('parent_id', 'lFkBv4jn', ),
    ('author', 'UOLG-F0l', ),
    ('file', "D:\projects\cedric05-data-storage-api-java\apis\put.http")
)



Url Join Usecases (most of them are not covered, and its not intuitive)

  1. both ending with /
  2. parent ending with /
  3. child ending with /
  4. none
  5. parent has url params, and not defined in url
  6. parent has url params defined in url
  7. child has urlparams, and not defined in url
  8. child has urlparams defined in url

Examples for

@name(usecase1)
GET https://req.dothttp.dev/user

@name(sub)
GET "/profile"
/*
    https://req.dothttp.dev/user/profile
*/


@name(usecase2)
GET https://req.dothttp.dev/user

@name(sub2)
GET "profile"

/*
    https://req.dothttp.dev/user/profile
*/



@name(usecase3)
GET https://req.dothttp.dev/user/

@name(sub3)
GET "/profile"

/*
    https://req.dothttp.dev/user/profile
*/





@name(usecase4)
GET https://req.dothttp.dev/user/

@name(sub4)
GET "profile"

/*
    https://req.dothttp.dev/user/profile
*/




@name(usecase5)
GET https://req.dothttp.dev/user/?ramu=ranga

@name(sub5)
GET "profile"

/*
    https://req.dothttp.dev/user/profile
*/






@name(usecase6)
GET https://req.dothttp.dev/user/
?ramu=ranga

@name(sub6)
GET "profile"

/*
    https://req.dothttp.dev/user/profile
*/





@name(usecase7)
GET https://req.dothttp.dev/user/

@name(sub7)
GET "profile?ramu=ranga"


/*
    https://req.dothttp.dev/user/profile?ramu=ranga
*/




@name(usecase8)
GET https://req.dothttp.dev/user/

@name(sub8)
GET "profile"
?ramu=ranga

/*
    https://req.dothttp.dev/user/profile?ramu=ranga
*/

Pending features

  • stdin support
  • curl import
  • default headers defined in prop file
  • property value in http file itself
  • property syntax with double paranthesis
  • comments
  • name request?
  • shebang support
  • payload 's data should support json - -> form input

Postman import improvements

  • shouldn't overwrite files (add (1)/(2) like downloads)
  • support option not create files(respond with json)
  • support disabled (create duplicate http def)
  • bug urldecode query value

History item execute not working properly

steps to reproduce:

  1. create below file
  2. execute
  3. reopen http file
  4. execute, (you will run into error)
POST https://api.spacex.land/graphql

json(
    {
        "query":"{
  dragons {
    description
    dry_mass_kg
    active
  }
}
",
        "variables":null
    }
)

could be issue with dothttp

Import swagger

swagger has multiple versions, support will be provided for version 2(most used)
Upon usage we may want to support more versions

Postman import/export with inherit auth

Currently if inherit auth is enabled, auth info is added to all requests.

Now that extend request is available, leveraging this help better manage requests

skip 0.0.15

version has regressions. so will not be used in latest dothttp-runner

[busyboy] multipart upload text part is considered as file.

only happens for busyboy (nodejs) mulipart parser.

works perfectly fine with httpbin.org

POST "http://127.0.0.1:3000/api/v1/attachments/upload"

files(
    ('org_id', 'testsesrere'),
    ('parent_id', 'test'),
    ('author', 'test'),
    ('file', "D:\projects\cedric05-data-storage-api-java\apis\put.http")
)

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.